Giter Club home page Giter Club logo

sensors_async_sim's Introduction

Sensor Simulation with AsyncIO

This is a simple example of how to use asyncio to simulate async reading from sensors and write it to a database (either mongo or sqlite).

Requirements

Mosquitto is needed for mqtt messaging.

SQLite3 is needed for managing the DB.

(Optional) MongoDB is needed for managing the DB.

Virtualenv provided:

  • python 3.7
  • asyncio 3.4.3
  • numpy 1.16.2
  • paho-mqtt 1.4.0
  • pymongo 3.7.2

How it works

There are 3 main files:

  • initsqlite.py initializes the database and defines the schema to be used.
  • sensors.py uses asyncio to simulate data from different sensors and publishes those readings through mqtt.
  • subscriber.py subscribes to the different topics and writes everything on a database.

Always run initsqlite.py first to create or reset the database. Then, run subscriber.py to start listening and don't lose any message and finally run sensors.pyto start publishing the data.

How to run

On Ubuntu

First install all the requirements:

apt-get install mosquitto
apt-get install sqlite3 mongodb-org
$ git clone https://github.com/HernanG234/sensors_async_sim.git
$ cd sensors_async_sim
$ git checkout sample
$ source venv/bin/activate
# You should see (venv) at the beggining of your terminal
(venv) $ python initsqlite.py
(venv) $ python subscriber.py

# Open a new terminal
$ source venv/bin/activate
(venv) $ python sensors.py

If you are not using the virtualenv provided, install the requirements using pip and then run the steps above:

$ pip install -r requirements.txt

Check that everything worked from SQLite:

$ sqlite3 iot-sqlite.db
sqlite> .tables
frequency     pressure      temperature
sqlite> select * from pressure;
# You should see the readings here!

On Windows

Install all the requirements:

Execute each in a separate PowerShell:

.\mosquitto

python initsqlite.py
python subscriber.py
python sensors.py

Once it is finished, you can check that it worked from sqlite:

sqlite3.exe

Inside Sqlite:

.open iot-sqlite.db
.tables
select * from pressure;

Upcoming features

  • MQTT messaging
  • Implement writing to mongo.
  • Implement writing to sqlite.
  • Add "signals" to sensors (noise, step, ramp, etc.) to plot ant query sth nicer
  • Accept arg to select mongo or sqlite.
  • Plot

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.