PurpleRose
c157f4b0c8
|
4 years ago | |
---|---|---|
ArduinoScript | 4 years ago | |
InfluxDB&Grafana_Compose | 4 years ago | |
MyConsumer | 4 years ago | |
MyServer | 4 years ago | |
My_Producer | 4 years ago | |
README.md | 4 years ago |
README.md
Project for IoT
This project implement a communication method publish/subscribe using RabbitMQ Broker. This implement adds functions as, write of the values receipt to a database in order to represent and to send these same values to a remote server for further procedure.
Architecture
This architecture is divided into 5 big parts :
-
The producer who produce and send the values to the broker.
-
The RabbitMQ broker which stores temporarily the values sent by the producer.
-
The consumer which consumes the stored values from the broker.
-
The database and the monitoring tool, into which the values stored and projected.
-
The remote server where the values sent for further procedure.
In particular this architecture is the following:
Components
- Arduino Uno
- TMP36Gz temp sensor
- Raspberry Pi 3
- Desktop PC with Docker
Project Setup
- Download the repository from the website of swarmlab link. Thus, we have handy 5 folders, one per piece we have to setup.
Αrduino
Beginning with Arduino, we have to connect it with our computer and the connecting platform Arduino IDE (if not present download and install it) link in order to insatll the code in the file readTempValuesFromArduino.ino of Arduino.
Possible issue in the code transfer to Arduino:
[can't open device "/dev/ttyUSB0": Perm. denied (Linux permissions)]
Solution: Open the terminal of the system and type:
sudo chmod ugo+w /dev/ttyUSB0
The same command must be run to the raspberry upon we connect to Αrduino.
Sensor's Connection to Arduino
As shown in the architecture's picture above, the sensor includes three (3) connections (Vcc, Gnd, Values). We connect the middle connector to the sensor with the analog input Α0 (as shown in the code) for receiving its values, the left connector to the Current (Vcc) and the right connector to the Ground (Gnd). (1) Based on the code of Arduino we are able to use the pin for the sensor's values from Α0 in any analog connection and we change the pin in the code also. (2) Also, we are able to change the value to the function delay in order of the quicker or slower sample receipt. (3) Click the button to compile. In the case which no errors occured... (4) Click the button to upload to Arduino.
Raspberry
Producer
Follow the steps concerning Raspberry here in order to gain access.
Upon we are in the system we transfer the downloaded files from the repository in the folder MyProducer (producer.js, package.json). Then, run the command:
npm install
To download all the dependencies needed to the script producer.js to run normally. Finally, run the command:
sudo chmod ugo+w /dev/ttyUSB0
In order Arduino to send the data through the serial connection. If not present the ttyUSB0 connection then run:
ls /dev/tty*
To detect all Raspberry connections and into which Arduino is connected. Repeat the change mode command (chmod) with the appropriate connection.
Docker
For working the rest of the services need to install Docker and the Docker Compose to the local computer. link.
Consumer
In the folder MyConsumer open a terminal computer. Then, run the command:
docker build -t myconsumer .
This command will create a docker image with the info needed to run the script consumer.js. Then, run the command:
docker run -it -p 5673:5673 myconsumer
To compose a container from the image for the consumer service.
As shown in the command run we expose the port 5673 from the computer to the port 5673 of the container.
Finally, we check if the container run using the command:
docker ps
Server
We use the same proceduce for the server. We go to the folder MyServer upon we startup a terminal. Then, we run the command:
docker build -t atticaregionserver .
This particular command will create a docker image with the info needed to run the script server.js. Then, we run the command:
docker run -it -p 4000:4000 atticaregionserver
To compose a container from the image for the server service.
As shown in the command run we expose the port 4000 from the computer to the port 4000 of the container.
Finally, we check if the container run using the command:
docker ps
RabbitMQ
The next needed service is RabbitMQ broker(AMQP). Of its functions RabbitMQ (fanout, token routing, etc) we will use the Direct exchange.
At the beginning, we have to download the preset RabbitMQ image from the docker hub to run the command:
docker run -d -p 15672:15672 -p 5672:5672 --name rabbitmq rabbitmq:3-management
The docker will download the image and will run it to expose the ports (default ports).
The port 15672 is using from the manager and the port 5672 is using for the broker.
Then, we go to the port of the manager(localhost:15672) for further adjustments. Upon info requst, we type guest as username and password. Then we have access of the manager.
Now, we are able to overview the process of produce and consume using the graphs, the speed of consume and produce to the tab Queues , the connection and the channels. Further, we are able to create a new user to the tab Admin.
Grafana & InfluxDB
At this point, except of the images of Grafana and of InfluxDB we will need a network in order Grafana to automatically detect the database. The structure we will use to obtain it is the following:
To obtain the structure above we create a docker network with the command:
docker network create influxDB_Grafana_network
To detect the available networks we use the command:
docker network ls
Also, two volumes will be needed to avoid data lose of the database and of Grafana everytime which the containers close. We create those two volumes using the following commands:
docker volume create grafana_volume
docker volume create influxdb_volume
To detect the available volumes we use the command:
docker volume ls
The next step is to go to the folder InfluxDB&Grafana compose to run the command:
docker-compose up -d
This command will create the content of the docker-compose.yml file.
As shown to the file above with the yml file compose two containers(InfluxDB,Grafana) for using the common network bridge network and the corresponding volumes.
Upon composing the containers using the command:
docker exec -it influxdb_container sh
We are able to access the shell in the container of the InfluxDB. Then, we type influx to go to shell of the InfluxDB. The, we create our database with the command:
create database values_from_sensor
Now, we are able to see the database we already create, with the command:
show databases
Grafana (setup)
The next step is to go to the application of Granafa which run at the port 3000. We type to our browser the address localhost:3000. The initial info for username and password are both admin.
Now, we have to set the data source, which in our case is InfluxDB.
Fill the database info:
Then, we click Save and Test
Dashboard Creation
Choose the data source we already create and then the measurement we wish to project.
More adjustments for better presentation of the values of the tab Panel at the right of the screen.
Namespaces & rooms
Indicative Project Run
Waiting for producer's data
Temperature rise above of 40%
User's Notification
Sources
https://git.swarmlab.io:3000/zeus/iot-swarm-example/raw/branch/master/docs/README.adoc#_server_site
http://docs.swarmlab.io/SwarmLab-HowTos/labs/IoT/SensorNode2Server.adoc.html
https://www.influxdata.com/blog/getting-started-with-node-influx/
https://www.rabbitmq.com/tutorials/tutorial-one-javascript.html
https://node-influx.github.io/class/src/index.js~InfluxDB.html
https://www.thedevstop.com/metric-visualization-with-node-influxdb-and-grafana/
https://github.com/vicanso/influxdb-nodejs
https://www.w3schools.com/nodejs/nodejs_email.asp
https://docs.influxdata.com/influxdb/v1.8/query_language/explore-data/