Compare commits

...

No commits in common. 'aeb71b15b4dc24c59c332f47c32b0004579823e0' and '69a4666e7482890ca1946157e4a17d3ecdff553b' have entirely different histories.

  1. 350
      LICENSE
  2. 2
      README.md
  3. 421
      iot.adoc
  4. 469
      json.adoc
  5. BIN
      script_install_photos/10th_influxdb_conf.png
  6. BIN
      script_install_photos/11th_influxdb_user_creation.png
  7. BIN
      script_install_photos/12th_graphana_import.png
  8. BIN
      script_install_photos/12th_graphana_import_small.png
  9. BIN
      script_install_photos/13th_graphana_import_menu.png
  10. BIN
      script_install_photos/14th_graphana_data_source.png
  11. BIN
      script_install_photos/15th_graphana_data_source_config.png
  12. BIN
      script_install_photos/1st_stop_&_selections.png
  13. BIN
      script_install_photos/1st_stop_&_selections2.png
  14. BIN
      script_install_photos/2nd_stop_hostname_selection.png
  15. BIN
      script_install_photos/2nd_stop_hostname_selection2.png
  16. BIN
      script_install_photos/3rd_stop_Node_red_dashboard_username.png
  17. BIN
      script_install_photos/4th_stop_Node_red_dashboard_password.png
  18. BIN
      script_install_photos/6th_stop_admin_name_node_red_&_MQQT.png
  19. BIN
      script_install_photos/7th_stop_Node_red_&_MQQT._password.png
  20. BIN
      script_install_photos/8th_stop_smb.conf.png
  21. BIN
      script_install_photos/9th_old_node.js.png
  22. BIN
      script_install_photos/add_data_source.png
  23. BIN
      script_install_photos/select_InfluxDB.png

350
LICENSE

@ -1,350 +0,0 @@
Creative Commons Attribution-ShareAlike 4.0 International Creative Commons
Corporation ("Creative Commons") is not a law firm and does not provide legal
services or legal advice. Distribution of Creative Commons public licenses
does not create a lawyer-client or other relationship. Creative Commons makes
its licenses and related information available on an "as-is" basis. Creative
Commons gives no warranties regarding its licenses, any material licensed
under their terms and conditions, or any related information. Creative Commons
disclaims all liability for damages resulting from their use to the fullest
extent possible.
Using Creative Commons Public Licenses
Creative Commons public licenses provide a standard set of terms and conditions
that creators and other rights holders may use to share original works of
authorship and other material subject to copyright and certain other rights
specified in the public license below. The following considerations are for
informational purposes only, are not exhaustive, and do not form part of our
licenses.
Considerations for licensors: Our public licenses are intended for use by
those authorized to give the public permission to use material in ways otherwise
restricted by copyright and certain other rights. Our licenses are irrevocable.
Licensors should read and understand the terms and conditions of the license
they choose before applying it. Licensors should also secure all rights necessary
before applying our licenses so that the public can reuse the material as
expected. Licensors should clearly mark any material not subject to the license.
This includes other CC-licensed material, or material used under an exception
or limitation to copyright. More considerations for licensors : wiki.creativecommons.org/Considerations_for_licensors
Considerations for the public: By using one of our public licenses, a licensor
grants the public permission to use the licensed material under specified
terms and conditions. If the licensor's permission is not necessary for any
reason–for example, because of any applicable exception or limitation to copyright–then
that use is not regulated by the license. Our licenses grant only permissions
under copyright and certain other rights that a licensor has authority to
grant. Use of the licensed material may still be restricted for other reasons,
including because others have copyright or other rights in the material. A
licensor may make special requests, such as asking that all changes be marked
or described.
Although not required by our licenses, you are encouraged to respect those
requests where reasonable. More considerations for the public : wiki.creativecommons.org/Considerations_for_licensees
Creative Commons Attribution-ShareAlike 4.0 International Public License
By exercising the Licensed Rights (defined below), You accept and agree to
be bound by the terms and conditions of this Creative Commons Attribution-ShareAlike
4.0 International Public License ("Public License"). To the extent this Public
License may be interpreted as a contract, You are granted the Licensed Rights
in consideration of Your acceptance of these terms and conditions, and the
Licensor grants You such rights in consideration of benefits the Licensor
receives from making the Licensed Material available under these terms and
conditions.
Section 1 – Definitions.
a. Adapted Material means material subject to Copyright and Similar Rights
that is derived from or based upon the Licensed Material and in which the
Licensed Material is translated, altered, arranged, transformed, or otherwise
modified in a manner requiring permission under the Copyright and Similar
Rights held by the Licensor. For purposes of this Public License, where the
Licensed Material is a musical work, performance, or sound recording, Adapted
Material is always produced where the Licensed Material is synched in timed
relation with a moving image.
b. Adapter's License means the license You apply to Your Copyright and Similar
Rights in Your contributions to Adapted Material in accordance with the terms
and conditions of this Public License.
c. BY-SA Compatible License means a license listed at creativecommons.org/compatiblelicenses,
approved by Creative Commons as essentially the equivalent of this Public
License.
d. Copyright and Similar Rights means copyright and/or similar rights closely
related to copyright including, without limitation, performance, broadcast,
sound recording, and Sui Generis Database Rights, without regard to how the
rights are labeled or categorized. For purposes of this Public License, the
rights specified in Section 2(b)(1)-(2) are not Copyright and Similar Rights.
e. Effective Technological Measures means those measures that, in the absence
of proper authority, may not be circumvented under laws fulfilling obligations
under Article 11 of the WIPO Copyright Treaty adopted on December 20, 1996,
and/or similar international agreements.
f. Exceptions and Limitations means fair use, fair dealing, and/or any other
exception or limitation to Copyright and Similar Rights that applies to Your
use of the Licensed Material.
g. License Elements means the license attributes listed in the name of a Creative
Commons Public License. The License Elements of this Public License are Attribution
and ShareAlike.
h. Licensed Material means the artistic or literary work, database, or other
material to which the Licensor applied this Public License.
i. Licensed Rights means the rights granted to You subject to the terms and
conditions of this Public License, which are limited to all Copyright and
Similar Rights that apply to Your use of the Licensed Material and that the
Licensor has authority to license.
j. Licensor means the individual(s) or entity(ies) granting rights under this
Public License.
k. Share means to provide material to the public by any means or process that
requires permission under the Licensed Rights, such as reproduction, public
display, public performance, distribution, dissemination, communication, or
importation, and to make material available to the public including in ways
that members of the public may access the material from a place and at a time
individually chosen by them.
l. Sui Generis Database Rights means rights other than copyright resulting
from Directive 96/9/EC of the European Parliament and of the Council of 11
March 1996 on the legal protection of databases, as amended and/or succeeded,
as well as other essentially equivalent rights anywhere in the world.
m. You means the individual or entity exercising the Licensed Rights under
this Public License. Your has a corresponding meaning.
Section 2 – Scope.
a. License grant.
1. Subject to the terms and conditions of this Public License, the Licensor
hereby grants You a worldwide, royalty-free, non-sublicensable, non-exclusive,
irrevocable license to exercise the Licensed Rights in the Licensed Material
to:
A. reproduce and Share the Licensed Material, in whole or in part; and
B. produce, reproduce, and Share Adapted Material.
2. Exceptions and Limitations. For the avoidance of doubt, where Exceptions
and Limitations apply to Your use, this Public License does not apply, and
You do not need to comply with its terms and conditions.
3. Term. The term of this Public License is specified in Section 6(a).
4. Media and formats; technical modifications allowed. The Licensor authorizes
You to exercise the Licensed Rights in all media and formats whether now known
or hereafter created, and to make technical modifications necessary to do
so. The Licensor waives and/or agrees not to assert any right or authority
to forbid You from making technical modifications necessary to exercise the
Licensed Rights, including technical modifications necessary to circumvent
Effective Technological Measures. For purposes of this Public License, simply
making modifications authorized by this Section 2(a)(4) never produces Adapted
Material.
5. Downstream recipients.
A. Offer from the Licensor – Licensed Material. Every recipient of the Licensed
Material automatically receives an offer from the Licensor to exercise the
Licensed Rights under the terms and conditions of this Public License.
B. Additional offer from the Licensor – Adapted Material. Every recipient
of Adapted Material from You automatically receives an offer from the Licensor
to exercise the Licensed Rights in the Adapted Material under the conditions
of the Adapter's License You apply.
C. No downstream restrictions. You may not offer or impose any additional
or different terms or conditions on, or apply any Effective Technological
Measures to, the Licensed Material if doing so restricts exercise of the Licensed
Rights by any recipient of the Licensed Material.
6. No endorsement. Nothing in this Public License constitutes or may be construed
as permission to assert or imply that You are, or that Your use of the Licensed
Material is, connected with, or sponsored, endorsed, or granted official status
by, the Licensor or others designated to receive attribution as provided in
Section 3(a)(1)(A)(i).
b. Other rights.
1. Moral rights, such as the right of integrity, are not licensed under this
Public License, nor are publicity, privacy, and/or other similar personality
rights; however, to the extent possible, the Licensor waives and/or agrees
not to assert any such rights held by the Licensor to the limited extent necessary
to allow You to exercise the Licensed Rights, but not otherwise.
2. Patent and trademark rights are not licensed under this Public License.
3. To the extent possible, the Licensor waives any right to collect royalties
from You for the exercise of the Licensed Rights, whether directly or through
a collecting society under any voluntary or waivable statutory or compulsory
licensing scheme. In all other cases the Licensor expressly reserves any right
to collect such royalties.
Section 3 – License Conditions.
Your exercise of the Licensed Rights is expressly made subject to the following
conditions.
a. Attribution.
1. If You Share the Licensed Material (including in modified form), You must:
A. retain the following if it is supplied by the Licensor with the Licensed
Material:
i. identification of the creator(s) of the Licensed Material and any others
designated to receive attribution, in any reasonable manner requested by the
Licensor (including by pseudonym if designated);
ii. a copyright notice;
iii. a notice that refers to this Public License;
iv. a notice that refers to the disclaimer of warranties;
v. a URI or hyperlink to the Licensed Material to the extent reasonably practicable;
B. indicate if You modified the Licensed Material and retain an indication
of any previous modifications; and
C. indicate the Licensed Material is licensed under this Public License, and
include the text of, or the URI or hyperlink to, this Public License.
2. You may satisfy the conditions in Section 3(a)(1) in any reasonable manner
based on the medium, means, and context in which You Share the Licensed Material.
For example, it may be reasonable to satisfy the conditions by providing a
URI or hyperlink to a resource that includes the required information.
3. If requested by the Licensor, You must remove any of the information required
by Section 3(a)(1)(A) to the extent reasonably practicable.
b. ShareAlike.In addition to the conditions in Section 3(a), if You Share
Adapted Material You produce, the following conditions also apply.
1. The Adapter's License You apply must be a Creative Commons license with
the same License Elements, this version or later, or a BY-SA Compatible License.
2. You must include the text of, or the URI or hyperlink to, the Adapter's
License You apply. You may satisfy this condition in any reasonable manner
based on the medium, means, and context in which You Share Adapted Material.
3. You may not offer or impose any additional or different terms or conditions
on, or apply any Effective Technological Measures to, Adapted Material that
restrict exercise of the rights granted under the Adapter's License You apply.
Section 4 – Sui Generis Database Rights.
Where the Licensed Rights include Sui Generis Database Rights that apply to
Your use of the Licensed Material:
a. for the avoidance of doubt, Section 2(a)(1) grants You the right to extract,
reuse, reproduce, and Share all or a substantial portion of the contents of
the database;
b. if You include all or a substantial portion of the database contents in
a database in which You have Sui Generis Database Rights, then the database
in which You have Sui Generis Database Rights (but not its individual contents)
is Adapted Material, including for purposes of Section 3(b); and
c. You must comply with the conditions in Section 3(a) if You Share all or
a substantial portion of the contents of the database.
For the avoidance of doubt, this Section 4 supplements and does not replace
Your obligations under this Public License where the Licensed Rights include
other Copyright and Similar Rights.
Section 5 – Disclaimer of Warranties and Limitation of Liability.
a. Unless otherwise separately undertaken by the Licensor, to the extent possible,
the Licensor offers the Licensed Material as-is and as-available, and makes
no representations or warranties of any kind concerning the Licensed Material,
whether express, implied, statutory, or other. This includes, without limitation,
warranties of title, merchantability, fitness for a particular purpose, non-infringement,
absence of latent or other defects, accuracy, or the presence or absence of
errors, whether or not known or discoverable. Where disclaimers of warranties
are not allowed in full or in part, this disclaimer may not apply to You.
b. To the extent possible, in no event will the Licensor be liable to You
on any legal theory (including, without limitation, negligence) or otherwise
for any direct, special, indirect, incidental, consequential, punitive, exemplary,
or other losses, costs, expenses, or damages arising out of this Public License
or use of the Licensed Material, even if the Licensor has been advised of
the possibility of such losses, costs, expenses, or damages. Where a limitation
of liability is not allowed in full or in part, this limitation may not apply
to You.
c. The disclaimer of warranties and limitation of liability provided above
shall be interpreted in a manner that, to the extent possible, most closely
approximates an absolute disclaimer and waiver of all liability.
Section 6 – Term and Termination.
a. This Public License applies for the term of the Copyright and Similar Rights
licensed here. However, if You fail to comply with this Public License, then
Your rights under this Public License terminate automatically.
b. Where Your right to use the Licensed Material has terminated under Section
6(a), it reinstates:
1. automatically as of the date the violation is cured, provided it is cured
within 30 days of Your discovery of the violation; or
2. upon express reinstatement by the Licensor.
c. For the avoidance of doubt, this Section 6(b) does not affect any right
the Licensor may have to seek remedies for Your violations of this Public
License.
d. For the avoidance of doubt, the Licensor may also offer the Licensed Material
under separate terms or conditions or stop distributing the Licensed Material
at any time; however, doing so will not terminate this Public License.
e. Sections 1, 5, 6, 7, and 8 survive termination of this Public License.
Section 7 – Other Terms and Conditions.
a. The Licensor shall not be bound by any additional or different terms or
conditions communicated by You unless expressly agreed.
b. Any arrangements, understandings, or agreements regarding the Licensed
Material not stated herein are separate from and independent of the terms
and conditions of this Public License.
Section 8 – Interpretation.
a. For the avoidance of doubt, this Public License does not, and shall not
be interpreted to, reduce, limit, restrict, or impose conditions on any use
of the Licensed Material that could lawfully be made without permission under
this Public License.
b. To the extent possible, if any provision of this Public License is deemed
unenforceable, it shall be automatically reformed to the minimum extent necessary
to make it enforceable. If the provision cannot be reformed, it shall be severed
from this Public License without affecting the enforceability of the remaining
terms and conditions.
c. No term or condition of this Public License will be waived and no failure
to comply consented to unless expressly agreed to by the Licensor.
d. Nothing in this Public License constitutes or may be interpreted as a limitation
upon, or waiver of, any privileges and immunities that apply to the Licensor
or You, including from the legal processes of any jurisdiction or authority.
Creative Commons is not a party to its public licenses. Notwithstanding, Creative
Commons may elect to apply one of its public licenses to material it publishes
and in those instances will be considered the "Licensor." The text of the
Creative Commons public licenses is dedicated to the public domain under the
CC0 Public Domain Dedication. Except for the limited purpose of indicating
that material is shared under a Creative Commons public license or as otherwise
permitted by the Creative Commons policies published at creativecommons.org/policies,
Creative Commons does not authorize the use of the trademark "Creative Commons"
or any other trademark or logo of Creative Commons without its prior written
consent including, without limitation, in connection with any unauthorized
modifications to any of its public licenses or any other arrangements, understandings,
or agreements concerning use of licensed material. For the avoidance of doubt,
this paragraph does not form part of the public licenses.
Creative Commons may be contacted at creativecommons.org.

2
README.md

@ -1,2 +0,0 @@
# iot

421
iot.adoc

@ -0,0 +1,421 @@
= Εργασία Εξαμήνου
Καραμιχάλης Κωνσταντίνος cse47455
:nofooter:
:toc: right
:toc-title: Πίνακας περιεχομένων
:toclevels: 6
:sectnums:
:data-uri:
:icons: font
:ext-relative: .adoc
:Figure-caption: Εικόνα
{empty} +
[WARNING]
====
[.text-center]
Προσοχή !!! +
Για την χρήση οποιουδήποτε σύστήματος *LINUX* παρακαλείστε να εκτελέσετε τις παρακάτω εντολές: +
[.text-center]
*sudo apt-get remove --purge vim** +
*sudo apt-get install nano* +
{empty} +
[small]*_"I've been using VIM for about 2 years now, mostly because i don't know how to exit it..."_*
====
{empty} +
toc::[]
== Σκοπός εργασίας
[.text-justify]
Ο σκοπός της εργασίας μας είναι η η ανάγνωση δεδομένων απο έναν αισθητήρα κίνησης η αποθήκευση ή και αποστολή τους σε έναν server σε ένα σμήνος.
=== Ανάγνωση δεδομένων και αποστολή τους
[.text-justify]
Ο τρόπος που επιλέχθηκε για την πραγματοποίησει της εργασίας είναι :
[square]
* Χρήση του Arduino nano για την ανάγνωση των δεδομένων του αισθητήρα.
* Χρήση του Raspberry PI Zero W για την επεξεργασία και την αποστολή των δεδομένων μας στον server.
== Συνδεσμολογία και επικοινωνία.
[.text-justify]
Για την επικοινωνία μεταξύ raspberry και arduino, επιλέχθηκε να γίνει χρήση του πρωτόκολλου I2C και όχι του πρωτόκολλου σειριακής επικοινωνίας.
Αυτη η επιλογή μας δίνει το πλεονέκτημα, να μπορούμε να χρησιμοποιήσουμε το Serial Monitor του arduino, ταυτοχρονα με την επικοινωνία του με το
raspberry για χρήση debugging ή για οτιδήποτε άλλο. Το μειονέκτημα της επιλογής είναι άυξηση της πολυπλοκότητας του κωδικα μας αλλά και την
ανάγκη ειδικών διατάξεων για την πραγματοποιήσει της επικοινωνίας (Logic level converter).
{empty} +
{empty} +
Το arduino χρησιμοποιεί λογική των 5V στις εισόδους/εξόδους του ενώ το raspberry 3,3V, αυτό έχει ως αποτέλεσμα ενώ μπορέι το arduino να διαβάσει τα δεδομένα
που του αποστέλλονται απο το raspberry στην αποστολή των δεδομένων απο το arduino προς το raspberry υπάρχει μεγάλος κίνδυνος να δημιουργήσουμε μόνιμη καταστροφή
στις εισόδους του ή και ολοκληρωτική καταστροφή του μικροεπεξεργαστη του raspberry. Για την αποφυγή οποιουδήποτε προβλήματος και την ακεραιότητα των δεδομένων μας
παρεμβάλλουμε στην μεταξύ τους σύνδεση εναν logic level converter.
[.text-center]
image::./photos/raspberry-pi-arduino-i2c-communication_bb-1080x675.png[750,750,title="Συνδεσμολογία"]
[.text-center]
image::./photos/LevelConverter.jpg[title="Logic level converter"]
{empty} +
== Κώδικας arduino (Slave)
[source,arduino]
----
#include <Wire.h> <1>
#include <stdlib.h>
#define SLAVE_ADDRESS 0x16 <2>
const int xpin = A0; // x-axis of the accelerometer <3>
const int ypin = A1; // y-axis <3>
const int zpin = A2; // z-axis (only on 3-axis models) <3>
int index = 0; <4>
char data[40]; <5>
void setup() {
Serial.begin(9600); <6>
pinMode(xpin, INPUT);
pinMode(ypin, INPUT); <7>
pinMode(zpin, INPUT);
// initialize i2c as slave
Wire.begin(SLAVE_ADDRESS); <2>
Wire.setClock(400000); <2>
Wire.onRequest(sendData); <8>
}
void loop() {
// Nothing to do at last !!!!
}
void sendData() {
read_lilypad(); <9>
Wire.write(data[index]); <10>
++index;
if (index >= 40) {
index = 0;
}
}
void read_lilypad () {
int x_input = analogRead(xpin); <11>
int y_input = analogRead(ypin); <11>
int z_input = analogRead(zpin); <11>
float x_zero_G = 515.39; <12>
float y_zero_G = 508.57; <12>
float z_zero_G = 513.19; <12>
float scale = 102.3; <13>
String x_value = String(((float)x_input - x_zero_G) / scale); <14>
String y_value = String(((float)y_input - x_zero_G) / scale); <14>
String z_value = String(((float)z_input - x_zero_G) / scale); <14>
String lilypad = "Lilypad x: " + x_value + " y: " + y_value + " z: " + z_value; <15>
lilypad.toCharArray(data, 40); <16>
}
----
<1> Βιβλιοθήκες για την λειτουργία του προγραμμάτος
<2> Δήλωση διέυθυνσης του Arduino στο δίκτύο I2C, Ένταξη στο δικτυο I2C ως slave, Ορισμός της ταχύτητας επικοινωνίας μεταξύ master και slave
<3> Ονοματοδοσία ακροδεκτών
<4> Μετρητής
<5> Πίνακας για την αποθήκευση των προς αποστολή δεδομένων
<6> Εκκίνηση σειριακής επικοινωνίας
<7> Δήλωση των ακροδεκτών ως είσοδο
<8> Δήλωση ποιας συνάρτησης θα χρησιμοποιηθεί όταν ο master του I2C δικτυώματος ζητήσει δεδομένα
<9> Κλήση συνάρτησης read_lilypad
<10> Αποστολή των δεδομένων στον master 1Byte κάθε φορά
<11> Διάβασμα των τιμών απο τον αισθητήρα.
<12> Οι τιμές zero_G είναι οι τιμές που πρέπει αναμένουμε απο τους αισθητήρες όταν βρίσκονται σε ακινησία.
Τις αφαιρούμε απο τις μετρήσεις μας για να έχουμε σωστά αποτέλεσμα στις μετρήσεις μας.
<13> Scale είναι το μέγεθος που περιμένουμε να μεταβληθεί η τιμή απο τον αισθητήρα μας όταν η επιτάχυνση σε κάποιον άξονα είναι ίση με 1G
<14> Αφαιρώντας απο την τιμή του αισθητήρα την τιμή _zero και το αποτέλεσμα τους το διαιρέσουμε με το scale έχουμε ώς αποτέλεσμα την επιτάχυνση ως προς το κάθε άξονα σε G έπειτα περναμε με την τιμή αυτή σε ένα string.
<15> Δημιουργία string με κατάλληλα μηνύματα και τις τιμές απο τον αισθητήρα
<16> Αποθήκευση του string στον πίνακα Data, ώστε να γίνει η αποστολή του στον master.
{empty} +
== Κώδικας Python στο Raspberry PI (Master)
[source,python]
----
import smbus <1>
import time <1>
import signal <1>
import re <1>
from datetime import datetime <1>
bus = smbus.SMBus(1) <2>
address = 0x16 <3>
print ("Reading Data from I2C bus")
while True:
try:
now = datetime.now() <4>
data = "" <5>
for i in range(0, 50):
data += chr(bus.read_byte(address)) <6>
date_time = now.strftime("%m/%d/%Y, %H:%M:%S") <7>
file = open("sensor_logs", "a") <8>
file.write(date_time +" "+ data + "\n") <9>
file.close() <10>
find_values = re.findall(r'[-\d]*[.][\d]+', data) <11>
create_list = list(map(str,find_values)) <12>
x_value = (create_list[0]) <13>
y_value = (create_list[1]) <13>
z_value = (create_list[2]) <13>
print (data)
time.sleep(1) <14>
except KeyboardInterrupt: <15>
print("\n"+"Interrupt detected Stopping program")
exit(0)
----
<1> Βιβλιοθήκες για την λειτουργία του προγραμμάτος.
<2> Επιλογή ποιου απο τα 2 I2C κανάλια χρησιμοποιούμε.
<3> Δήλωση της διέυθυνσης του Slave που θα ζητήσουμε δεδομένα.
<4> Δημιουργία Timestamp και αποθήκευση της τιμής στην μεταβλητη now.
<5> Δημιουργία μεταβλητης για την αποθήκευση των δεδομένων που θα ληφθούν απο το Arduino.
<6> Βρογχος για την λήψη των 50 Bytes από το Arduino 1 προς 1.
<7> Μορφοποίησει του Timestamp.
<8> Άνοιγμα του αρχείου έαν υπάρχει και εγγραφή των τιμών στο τέλος του αρχείου, αλλιώς δημιουργία του αρχέιου και εγγραφή των τιμών.
<9> Εγγραφή των δεδομένων με Timestamp στο αρχείου.
<10> Κλείσιμο του αρχέιου.
<11> "Καθαρισμός" του αρχέιου με χρήση Regex ώστε να απομονώσουμε μόνο τις τιμές.
<12> Δημιουργία λίστας με τις απομονωμένες τιμες.
<13> Ανάθεση των τιμών της λίστας σε μεταβλητή.
<14> Περίμενε ένα δευτερόλεπτο μέχρι να διαβάσεις πάλι τιμές (εάν δεν το βάλουμε ο κανάλι επικοινωνίας θα μέινει μόνιμα ανοιχτό και θα πέρνουμε συνέχεια δεδομένα).
<15> Αναγνωρίζει την διακόπή του προγραμμάτος απο τον χρήστη και "καθαρίζει" ότι προσωρινό αρχείο είχε δημιουργηθεί κατά την εκτέλεση του προγραμμάτος μας.
{empty} +
== Graphana & influxDB
[.text-justify]
Για την πραγματοποίηση της εργασίας μας χρησιμοποιήθηκε το εργαλέιο Graphana για την εικονικοποίηση των δεδομένων σε γραφήματα
και η για την αποθήκευση των δεδομένων επιλέχθηκε η βάση δεδομένων InfluxDB.
[.text-justify]
=== Graphana
Το Graphana είναι μία δικτυακή εφαρμογή που με τις κατάλληλες ρυθμίσεις μπορέι να παρέχει διαγράμματα,
γραφήματα η ακόμα και ειδοποιήσεις με τα δεδομένα που διαβάζει απο τα data sources της. https://grafana.com/
=== InfluxDb
Η βάση δεδομένων InfluxDB είναι παρομοια με μία βάση τύπου SQL αλλά με αρκετές διαφορές.
Η InfluxDB είναι σχεδιασμένη ειδικα για να διαχειρίζεται δεδομένα προσανατολισμένα προς τον χρόνο.
Ενώ και οι κλασσικές SQL βάσεις έχουν την ικανοτητα να διαχειριστούν τέτοιου τύπου δεδομένα δεν έχουν
την ικανότητα να διαχειριστούν μεγάλο όγκο και υψηλής συχνότητα τέτοιου τύπου δεδομένα.
Αυτό το κενό ήρθε να καλύψει η InfluxDB με την ικανότητα της για ανάλυση και αποθήκευση τέτοιου τύπου δεδομένων σε πραγματικό χρόνο. https://www.influxdata.com/
=== Εγκατάσταση Graphana & influxDB
[WARNING]
[.text-justify]
Ο οδηγός αυτός απευθύνεται για Εγκατάσταση είτε σε Raspberry Pi 3 και νεότερο, είτε σε υπολογιστές που έχουν εγκαταστήσει το Raspberry Pi OS
για οποιαδήποτε, άλλη χρήση θα δημιουργηθούν μικροπροβλήματα που θα πρέπει να αντιμετωπιστούν απο εσάς ανάλογα το σύστημα σας. +
[.text-center]
Η Εγκατάσταση καθώς και η χρήση των παραπάνω εργαλέιων έγινε σε Raspberry Pi 4
[.text-justify]
To script εγκαθιστά και περαιτερω εργαλέια που ίσως να μην είναι χρήσιμα για όλους όπως Node RED, Log2ram, Mosquitto MQTT Broker etc. Δίνεται όμως η επιλογή για μη εγκατάσταση τους
==== Κατέβασμα και εκτέλεση του αυτοματοποιημένου script
Κατεβάζουμε το script με την εντολή:
[.text-center]
wget https://bitbucket.org/api/2.0/snippets/scargill/kAR5qG/master/files/script.sh
Στην συνέχεια εκτελούμε:
[.text-center]
bash ./script.sh
[.text-justify]
Η Εγκατάσταση θα ξεκινήσει και μετά απο την ολοκλήρωση κάποιων πρώτων εγκαταστάσεων θα γίνει η πρώτη διακοπή για να μας ρωτήσει τι θα χρειαστούμε
να εγκαταστήσουμε
[.text-center]
image::./script_install_photos/1st_stop_&_selections2.png[750,750,title="Επιλογή"]
[IMPORTANT]
Δεν πρέπει να επιλέξουμε ταυτόχρονα nodenew με τα nodejs και nodered επιλέγουμε μόνο nodenew
Η δευτερη διακοπή θα μας ζητήσει εάν θέλουμε να αλλάξουμε το Hostname η να το αφήσουμε Default
[.text-center]
image::./script_install_photos/2nd_stop_hostname_selection2.png[750,750,title="Hostname"]
Η τριτη θα μας ζητήσει να θέσουμε ένα username για το Dashboard του node red Dashboard
[.text-center]
image::./script_install_photos/3rd_stop_Node_red_dashboard_username.png[750,750,title="Dashboard username"]
Η τέταρτη διακοπή θα μας ζητήσει να θέσουμε password για το Dashboard του node red Dashboard και η πέμπτη την επιβεβαίωση του κωδικού
[.text-center]
image::./script_install_photos/4th_stop_Node_red_dashboard_password.png[750,750,title="Dashboard password"]
Η έκτη διακοπή θα μας ζητήσει ένα admin name για το Node-Red και για το MQTT
[.text-center]
image::./script_install_photos/6th_stop_admin_name_node_red_&_MQQT.png[750,750,title="Admin name"]
Η Έβδομη διακοπή θα μας ζητήσει ένα admin password για το Node-Red και για το MQTT και η όγδοη την επιβεβαίωση του κωδικού
[.text-center]
image::./script_install_photos/7th_stop_Node_red_&_MQQT._password.png[750,750,title="Admin password"]
Η ένατη διακοπή θα μα ζητήσει να επιβεβαιώσουμε κάποιες πληροφορίες για πως γίνεται η αποκτηση IP στο σύστημα μας
[.text-center]
image::./script_install_photos/8th_stop_smb.conf.png[750,750,title="SMB Conf"]
[TIP]
[.text-justify]
Μετά απο αυτές τις διακοπές η εγκατάσταση θα συνεχίστεί και θα διαρκέσει αρκετή ώρα κατά πάσα πιθανότητα πάνω απο 25 λεπτά.
[NOTE]
[.text-justify]
Υπάρχει πιθανότητα η εγκατάσταση να διακοπέι ώστε να μας γίνουν περαιτερω ερωτήσεις για την εγκατάσταση επιλέγουμε ανάλογα με της ιδιοσυγκρασίες του συστηματός μας
Τέλος αφού ολοκληρωθέι η εγκατάσταση κάνουμε επανεκκίνηση του συστήματος μας.
=== Ρύθμιση InfluxDB
[.text-justify]
Αφού ολοκληρωθέι η επανεκκίνηση του συστήματος μας χρειάζονται 2 αλλαγές στο αρχείο ρυθμίσεων της InfluxDB. +
Με καποιον editor της επιλογης μας ανοίγουμε το αρχείο infuxdb.conf με δικαιώματα sudo.
[.text-center]
sudo nano /etc/influxldb/influxdb.conf
Και αναζητούμε τις εγγραφές
[source]
-------------------
[http]
# Determines whether HTTP endpoint is enabled.
enabled = true <1>
# Determines whether the Flux query endpoint is enabled.
# flux-enabled = false
# Determines whether the Flux query logging is enabled.
# flux-log-enabled = false
# The bind address used by the HTTP service.
bind-address = ":8086" <2>
-------------------
<1> Αφαιρούμε την δίεση για να ενεργοποιηθεί η λειτουργία.
<2> Αφαιρούμε την δίεση για να ενεργοποιηθεί η λειτουργία.
[.text-justify]
Στην σύνέχεια δημιουργούμε έναν χρήστη με δικαιώματα διαχειριστή στην βάση δεδομένων. +
Στην γραμμή εντολών πληκτρολογούμε influx
[source]
-------------------
pi@raspberry:~ $ influx
Connected to http://localhost:8086 version 1.8.3
InfluxDB shell version 1.8.3
> CREATE USER "pi" WITH PASSWORD 'raspberry' WITH ALL PRIVILEGES
> SHOW USERS
user admin
---- ----
pi true
> exit
-------------------
=== Ρύθμιση Graphana
[.text-justify]
Ανοίγουμε έναν browser και πληκτρολογούμε την διευθυνση του υπολογιστή που εγκαταστήσαμε το grafana και βάζουμε την port 3000
πχ http://127.0.0.1:3000 . Θα μας ζητηθεί να εισαγουμε username και password και τα δύο είναι admin,
αφού γίνει η σύνδεση θα μας ζητηθέι να αλλάξουμε το αρχικό password βάζουμε ένα της επιλογής μας και συνεχίζουμε.
[.text-justify]
Στο κεντρικό μενού πηγαίνουμε configuration Data Source
[.text-center]
image::./script_install_photos/14th_graphana_data_source.png[750,750,title="Data Source"]
Επιλέγουμε Add data source
[.text-center]
image::./script_install_photos/add_data_source.png[750,750,title="Add data source"]
Και μετά InfluxDB
[.text-center]
image::./script_install_photos/select_InfluxDB.png[750,750,title="Add data source"]
Στις ρυθμίσεις για το influxDB βάζουμε
[.text-center]
image::./script_install_photos/15th_graphana_data_source_config.png[750,750,title="Add data source",link="./script_install_photos/15th_graphana_data_source_config.png"]
Στην συνέχεια επιστρέφουμε στο κεντρικό μενου και επιλεγουμε Create import
[.text-center]
image::./script_install_photos/12th_graphana_import_small.png[750,750,title="Import"]
Upload JSON file
[.text-center]
image::./script_install_photos/13th_graphana_import_menu.png[750,750,title="Json"]
και ανεβάζουμε το αρχείο link:json{ext-relative}[JSON]
== Προσθήκες στον κώδικα της Python
Για να μπορέσουμε να τοποθετήσουμε τα δεδομένα στην βάση που μόλις δημιουργήσαμε θα πρέπει να γίνουν κάποιες προσθήκες στον κώδικα μας έτσι ώστε να στέλνονται τα δεδομένα ταυτόχρονα με τις άλλες λειτουργίες.
[source, python]
--------------------------
import smbus
import time
import re
from datetime import datetime
from influxdb import InfluxDBClient
client = InfluxDBClient('127.0.0.1', 8086, 'test', 'test', 'sensor') <1>
bus = smbus.SMBus(1)
address = 0x16
while True:
try:
now = datetime.now()
data = ""
for i in range(0, 40):
data += chr(bus.read_byte(address));
date_time = now.strftime("%m/%d/%Y, %H:%M:%S")
file = open("sensor_logs", "a")
file.write(date_time +" "+ data + "\n")
file.close()
find_values = re.findall(r'[-]{0,1}[\d]*[\.][\d]+', data)
create_list = list(map(str,find_values))
print (create_list)
print(create_list[0])
print(create_list[1])
print(create_list[2])
x_value = (create_list[0])
y_value = (create_list[1])
z_value = (create_list[2])
client.write(["logg,sensor_type=lilypad x_value="+x_value+",y_value="+y_value+",z_value="+z_value+""],{'db':'sensor'},204,'line') <2>
print (date_time+ " " + data)
print("\n")
time.sleep(1);
except KeyboardInterrupt:
print("\n"+"Interrupt detected Stopping program")
exit(0)
--------------------------
<1> Δημιουργία Σύνδεσης με την βάση (IP που βρίσκεται η βάση δεδομένων μας, Port που βρίσκεται η βάση δεδομένων μας, username του χρήστη για την βάση, password του χρήστη για την βάση, επιλογή βάσης)
<2> Αποστολή δεδομένων με την βάση (δημιουργία entry στην βάση sensor με τα δεδομένα που στάλθηκαν απο το Arduino)
Με τις προσθήκες αυτές πλέον ο κώδικας της Python λαμβάνει τα δεδομένα, τα γράφει σε ένα αρχείο τοπικά, τα εμφανίζει στην οθόνη μας και τα στέλνει προς την βάση δεδομένων για αποθήκευση.

469
json.adoc

@ -0,0 +1,469 @@
[source]
--------------------
{
"annotations": {
"list": [
{
"builtIn": 1,
"datasource": "-- Grafana --",
"enable": true,
"hide": true,
"iconColor": "rgba(0, 211, 255, 1)",
"name": "Annotations & Alerts",
"type": "dashboard"
}
]
},
"editable": true,
"gnetId": null,
"graphTooltip": 1,
"id": 3,
"links": [],
"panels": [
{
"aliasColors": {
"Data.distinct": "yellow",
"X": "yellow",
"Y": "red",
"logg.distinct": "purple"
},
"bars": false,
"dashLength": 10,
"dashes": false,
"datasource": null,
"fieldConfig": {
"defaults": {
"custom": {},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
},
{
"color": "red",
"value": 80
}
]
},
"unit": "accG"
},
"overrides": []
},
"fill": 0,
"fillGradient": 0,
"gridPos": {
"h": 9,
"w": 12,
"x": 0,
"y": 0
},
"hiddenSeries": false,
"id": 2,
"legend": {
"alignAsTable": false,
"avg": false,
"current": true,
"max": false,
"min": false,
"rightSide": false,
"show": true,
"total": false,
"values": true
},
"lines": true,
"linewidth": 2,
"nullPointMode": "null",
"options": {
"alertThreshold": false
},
"percentage": false,
"pluginVersion": "7.3.6",
"pointradius": 2,
"points": false,
"renderer": "flot",
"seriesOverrides": [],
"spaceLength": 10,
"stack": true,
"steppedLine": false,
"targets": [
{
"groupBy": [
{
"params": [
"$__interval"
],
"type": "time"
},
{
"params": [
"null"
],
"type": "fill"
}
],
"measurement": "Data",
"orderByTime": "ASC",
"policy": "default",
"refId": "A",
"resultFormat": "time_series",
"select": [
[
{
"params": [
"x_value"
],
"type": "field"
},
{
"params": [],
"type": "distinct"
}
]
],
"tags": [
{
"key": "sensor_type",
"operator": "=",
"value": "lilypad"
}
]
}
],
"thresholds": [],
"timeFrom": null,
"timeRegions": [],
"timeShift": null,
"title": "X_Values",
"tooltip": {
"shared": true,
"sort": 0,
"value_type": "individual"
},
"transparent": true,
"type": "graph",
"xaxis": {
"buckets": null,
"mode": "time",
"name": null,
"show": true,
"values": []
},
"yaxes": [
{
"decimals": null,
"format": "accG",
"label": "",
"logBase": 1,
"max": null,
"min": null,
"show": true
},
{
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": false
}
],
"yaxis": {
"align": false,
"alignLevel": null
}
},
{
"aliasColors": {
"Data.distinct": "semi-dark-purple"
},
"bars": false,
"dashLength": 10,
"dashes": false,
"datasource": null,
"fieldConfig": {
"defaults": {
"custom": {}
},
"overrides": []
},
"fill": 0,
"fillGradient": 0,
"gridPos": {
"h": 8,
"w": 12,
"x": 0,
"y": 9
},
"hiddenSeries": false,
"id": 6,
"legend": {
"avg": false,
"current": true,
"max": false,
"min": false,
"show": true,
"total": false,
"values": true
},
"lines": true,
"linewidth": 1,
"nullPointMode": "null",
"options": {
"alertThreshold": true
},
"percentage": false,
"pluginVersion": "7.3.6",
"pointradius": 2,
"points": false,
"renderer": "flot",
"seriesOverrides": [],
"spaceLength": 10,
"stack": false,
"steppedLine": false,
"targets": [
{
"groupBy": [
{
"params": [
"$__interval"
],
"type": "time"
},
{
"params": [
"null"
],
"type": "fill"
}
],
"measurement": "Data",
"orderByTime": "ASC",
"policy": "default",
"refId": "A",
"resultFormat": "time_series",
"select": [
[
{
"params": [
"y_value"
],
"type": "field"
},
{
"params": [],
"type": "distinct"
}
]
],
"tags": [
{
"key": "sensor_type",
"operator": "=",
"value": "lilypad"
}
]
}
],
"thresholds": [],
"timeFrom": null,
"timeRegions": [],
"timeShift": null,
"title": "Y_Values",
"tooltip": {
"shared": true,
"sort": 0,
"value_type": "individual"
},
"type": "graph",
"xaxis": {
"buckets": null,
"mode": "time",
"name": null,
"show": true,
"values": []
},
"yaxes": [
{
"format": "accG",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
},
{
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": false
}
],
"yaxis": {
"align": false,
"alignLevel": null
}
},
{
"aliasColors": {
"Data.distinct": "semi-dark-red",
"logg.distinct": "yellow"
},
"bars": false,
"dashLength": 10,
"dashes": false,
"datasource": null,
"fieldConfig": {
"defaults": {
"custom": {}
},
"overrides": []
},
"fill": 0,
"fillGradient": 0,
"gridPos": {
"h": 8,
"w": 12,
"x": 0,
"y": 17
},
"hiddenSeries": false,
"id": 8,
"legend": {
"avg": false,
"current": true,
"max": false,
"min": false,
"show": true,
"total": false,
"values": true
},
"lines": true,
"linewidth": 1,
"nullPointMode": "null",
"options": {
"alertThreshold": true
},
"percentage": false,
"pluginVersion": "7.3.6",
"pointradius": 2,
"points": false,
"renderer": "flot",
"seriesOverrides": [],
"spaceLength": 10,
"stack": false,
"steppedLine": false,
"targets": [
{
"groupBy": [
{
"params": [
"$__interval"
],
"type": "time"
},
{
"params": [
"null"
],
"type": "fill"
}
],
"measurement": "Data",
"orderByTime": "ASC",
"policy": "default",
"refId": "A",
"resultFormat": "time_series",
"select": [
[
{
"params": [
"z_value"
],
"type": "field"
},
{
"params": [],
"type": "distinct"
}
]
],
"tags": [
{
"key": "sensor_type",
"operator": "=",
"value": "lilypad"
}
]
}
],
"thresholds": [],
"timeFrom": null,
"timeRegions": [],
"timeShift": null,
"title": "Z_Values",
"tooltip": {
"shared": true,
"sort": 0,
"value_type": "individual"
},
"transparent": true,
"type": "graph",
"xaxis": {
"buckets": null,
"mode": "time",
"name": null,
"show": true,
"values": []
},
"yaxes": [
{
"format": "accG",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
},
{
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": false
}
],
"yaxis": {
"align": false,
"alignLevel": null
}
}
],
"refresh": false,
"schemaVersion": 26,
"style": "dark",
"tags": [],
"templating": {
"list": []
},
"time": {
"from": "now-20m",
"to": "now"
},
"timepicker": {
"hidden": false,
"refresh_intervals": [
"5s"
]
},
"timezone": "",
"title": "All values",
"uid": "ryopY-iRz",
"version": 7
}
--------------------

BIN
script_install_photos/10th_influxdb_conf.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

BIN
script_install_photos/11th_influxdb_user_creation.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

BIN
script_install_photos/12th_graphana_import.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 MiB

BIN
script_install_photos/12th_graphana_import_small.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 342 KiB

BIN
script_install_photos/13th_graphana_import_menu.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

BIN
script_install_photos/14th_graphana_data_source.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 218 KiB

BIN
script_install_photos/15th_graphana_data_source_config.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 139 KiB

BIN
script_install_photos/1st_stop_&_selections.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 74 KiB

BIN
script_install_photos/1st_stop_&_selections2.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 57 KiB

BIN
script_install_photos/2nd_stop_hostname_selection.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

BIN
script_install_photos/2nd_stop_hostname_selection2.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.9 KiB

BIN
script_install_photos/3rd_stop_Node_red_dashboard_username.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

BIN
script_install_photos/4th_stop_Node_red_dashboard_password.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.4 KiB

BIN
script_install_photos/6th_stop_admin_name_node_red_&_MQQT.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

BIN
script_install_photos/7th_stop_Node_red_&_MQQT._password.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.4 KiB

BIN
script_install_photos/8th_stop_smb.conf.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

BIN
script_install_photos/9th_old_node.js.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 62 KiB

BIN
script_install_photos/add_data_source.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 51 KiB

BIN
script_install_photos/select_InfluxDB.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 81 KiB

Loading…
Cancel
Save