Skip to content

Commit

Permalink
1rst verona residency update
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorgininho committed Aug 26, 2019
1 parent fc9a309 commit df91b71
Show file tree
Hide file tree
Showing 111 changed files with 4,797 additions and 0 deletions.
Binary file added source/_static/Lorawan nano-gateway.zip
Binary file not shown.
233 changes: 233 additions & 0 deletions source/_static/MQTT_arduinomkr1000.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,233 @@
//#include <ESP32HTTPUpdateServer.h>
//#include <EspMQTTClient.h>

/*
Name: MQTT_ESP12_HTU21
Created: 27/11/2017 12:35:40
Auteur: limpas guy
Projet objet connect� avec MQTT + Node-RED
*/
//#include <ESP8266WiFi.h>
#include <PubSubClient.h>
#include <SPI.h>
#include <WiFi101.h>
//include librairy for dht sensor
#include <DHT.h>
//include librairy for deep sleep
#include <RTCZero.h>


#define wifi_ssid "fablab_guest" // wifi SSID
#define wifi_password "veronafablab" // wifi pass

#define mqtt_server "192.168.50.55"
// #define mqtt_user "guest" //if mosquitto password protected
// #define mqtt_password "guest" //idem

#define temperatura_topic "stationMKR/temperatura" //Topic temperatura
#define umidita_topic "stationMKR/umidita" //Topic umidità
#define wtrlvl_topic "stationMKR/wtrlvl" //Topic water level

//conf for DHT sensor
#include <Adafruit_Sensor.h>
#include "DHT.h"
#define DHTPIN 6
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);

/* Create an rtc object */
RTCZero rtc;

/* Change these values to set the current initial time */
const byte seconds = 00;
const byte minutes = 00;
const byte hours = 00;

/* Change these values to set the current initial date */
const byte day = 24;
const byte month = 9;
const byte year = 16;

//boolean variable to change before looping
bool matched = false;

//conf for water level sensor
int WTRLVLPIN =7;
boolean Wtrlvl;

//Conf water pump command
int WTRPMPCMD =5;

//Buffer qui permet de d�coder les messages MQTT re�us
char message_buff[100];


long lastMsg = 0; //Horodatage du dernier message publi� sur MQTT

bool debug = true; //Affiche sur la console si True

WiFiClient espClient;
PubSubClient client(espClient);

void setup() {
Serial.begin(115200);

setup_wifi(); //connexion to wifi
client.setServer(mqtt_server, 1883); //connexion to MQTT server
client.setCallback(callback); //La fonction de callback qui est execut�e � chaque r�ception de message

dht.begin(); //DHT11 init
pinMode(WTRLVLPIN, INPUT); // set water level to input
digitalWrite(WTRLVLPIN, HIGH); // turn on pullup resistors

pinMode(WTRPMPCMD, OUTPUT);
digitalWrite(WTRPMPCMD, LOW);

delay(5000); //delay so we can see normal current draw
pinMode(LED_BUILTIN, OUTPUT); //set LED pin to output
digitalWrite(LED_BUILTIN, LOW); //turn LED off

rtc.begin(); //Start RTC library, this is where the clock source is initialized

rtc.setTime(hours, minutes, seconds); //set time
rtc.setDate(day, month, year); //set date

rtc.setAlarmTime(00, 00, 30); //set alarm time to go off in 30 seconds

//following two lines enable alarm, comment both out if you want to do external interrupt
rtc.enableAlarm(rtc.MATCH_HHMMSS); //set alarm
rtc.attachInterrupt(ISR); //creates an interrupt that wakes the SAMD21 which is triggered by a FTC alarm
//comment out the below line if you are using RTC alarm for interrupt
// extInterrupt(A1); //creates an interrupt source on external pin

//puts SAMD21 to sleep
rtc.standbyMode(); //library call
//samSleep(); //function to show how call works

}

//interrupt service routine (ISR), called when interrupt is triggered
//executes after MCU wakes up
void ISR()
{
matched =true;
pinMode(LED_BUILTIN, OUTPUT); //set LED pin to output
digitalWrite(LED_BUILTIN, LOW);

}

//function that sets up external interrupt
void extInterrupt(int interruptPin) {
pinMode(interruptPin, INPUT_PULLUP);
attachInterrupt(interruptPin, ISR, LOW);
}

//Connexion au r�seau WiFi:
void setup_wifi() {
delay(10);
Serial.println();
Serial.print("Connexion to ");
Serial.println(wifi_ssid);

WiFi.begin(wifi_ssid, wifi_password);

while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}

Serial.println("");
Serial.println("Connexion WiFi established ");
Serial.print("=> Addresse IP : ");
Serial.println(WiFi.localIP());
}

//Reconnexion :
void reconnect() {
//Boucle jusqu'� obtenur une reconnexion
while (!client.connected()) {
Serial.print("Connexion to MQTT...");
// (client.connect("MKRClient", mqtt_user, mqtt_password)) //For secured MQTT client
if (client.connect("MKRClient")) {
Serial.println("connected");
//Une fois connect�, on peut s'inscrire � un Topic
//par exemple : client.subscribe("outTopic/iotTopic")
client.subscribe("stationMKR/pumpcmd");
}
else {
Serial.print("failed : ");
Serial.print(client.state());
Serial.println("5 seconds before retry");
delay(5000);
}
}
}

void loop() {

if (!client.connected()) {
reconnect();
}
client.loop();

long now = millis();

float h = dht.readHumidity(); //read humidity on dht11
float t = dht.readTemperature(); // read temp on dht11
if (isnan(h) || isnan(t)) { h=0; t=0; } // put temp and humidity at 0 if wrong reading
delay(2000); //delay for dht11 reading


Wtrlvl=digitalRead(WTRLVLPIN); //getting waterlevel sensor value

client.publish(temperatura_topic, String(t).c_str(), true); //sending temp value
client.publish(umidita_topic, String(h).c_str(), true); //et l'humidit�
client.publish(wtrlvl_topic, String(Wtrlvl).c_str(), true);

pinMode(LED_BUILTIN, OUTPUT); //set LED pin to output
digitalWrite(LED_BUILTIN, LOW);

if (matched){
matched=false; //so it goes to this once after a wake up
rtc.setTime(hours, minutes, seconds); //set time
rtc.setDate(day, month, year); //set date

rtc.setAlarmTime(00, 30, 00); //set alarm time to go off in 10 seconds
rtc.standbyMode(); // Sleep until next alarm match
}
}

// D�clenche les actions � la r�ception d'un message
void callback(char* topic, byte* payload, unsigned int length) {
int i = 0;

/*
if (debug) {
Serial.println("Message recu => topic: " + String(topic));
Serial.print(" | longueur: " + String(length, DEC));
}
*/
// Lignes de code pour traitement des topics re�us :
for (i = 0; i<length; i++) {
message_buff[i] = payload[i];
}
message_buff[i] = '\0';

String msgString = String(message_buff);
/*
if (debug) {
Serial.println("Payload: " + msgString);
}
*/

if (msgString == "ON") {
digitalWrite(WTRPMPCMD, HIGH);
}
else {
digitalWrite(WTRPMPCMD, LOW);
}

}
1 change: 1 addition & 0 deletions source/_static/Nodred_flows.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"id":"686d65d5.97d88c","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"f1938efb.b3b16","type":"mqtt in","z":"686d65d5.97d88c","name":"","topic":"stationMKR/#","qos":"1","datatype":"auto","broker":"442d1ac5.343774","x":210,"y":80,"wires":[["2edbc32.3677a3c","42772348.76788c"]]},{"id":"b8650786.59d888","type":"mqtt out","z":"686d65d5.97d88c","name":"Pum command","topic":"stationMKR/pumpcmd","qos":"1","retain":"true","broker":"442d1ac5.343774","x":1000,"y":180,"wires":[]},{"id":"4b29a512.6fd13c","type":"mysql","z":"686d65d5.97d88c","mydb":"8bdd4b2a.669e28","name":"","x":680,"y":60,"wires":[["a18de386.c0b6d"]]},{"id":"e62b1ed1.d5125","type":"inject","z":"686d65d5.97d88c","name":"read DB","topic":"SELECT `temperatura`, `time` FROM `seedHydroTemp` ORDER BY `time` DESC LIMIT 10","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":100,"y":440,"wires":[[]]},{"id":"19e35447.2bc1ac","type":"inject","z":"686d65d5.97d88c","name":"inject DB","topic":"INSERT INTO `seedHydroTemp` (`id`, `temperatura`, `umidita`) VALUES (NULL, '27.25', '67.02');","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":100,"y":500,"wires":[[]]},{"id":"2edbc32.3677a3c","type":"function","z":"686d65d5.97d88c","name":"DB filter","func":"var temperatura=context.get('temperatura');\nvar umidita=context.get('umidita');\n\nif (msg.topic ==\"stationMKR/temperatura\")\n{\n temperatura = msg.payload;\n}\nelse if (msg.topic ==\"stationMKR/umidita\")\n{\n umidita = msg.payload;\n}\nelse if (msg.topic ==\"stationMKR/wtrlvl\")\n{\n temperatura=0;\n context.set('temperatura',temperatura);\n umidita=0;\n context.set('umidita',umidita);\n}\n\ncontext.set('temperatura',temperatura);\ncontext.set('umidita',umidita);\n\nmsg.payload = temperatura+\"&\"+umidita;\n\nif (temperatura!==0 && umidita!==0)\n{\n msg.topic =\"INSERT INTO `seedHydroTemp` (`id`, `temperatura`,`umidita`) VALUES (NULL, '\"+temperatura+\"','\"+umidita+\"');\"\n context.set('temperatura',0);\n context.set('umidita',0);\n return msg;\n \n}\n\n\n//return msg.payload\n","outputs":1,"noerr":0,"x":420,"y":60,"wires":[["4b29a512.6fd13c"]]},{"id":"e7603544.632d58","type":"ui_chart","z":"686d65d5.97d88c","name":"","group":"8a6026b4.4f4538","order":2,"width":0,"height":0,"label":"chart temperatura","chartType":"line","legend":"false","xformat":"auto","interpolate":"linear","nodata":"","dot":false,"ymin":"","ymax":"","removeOlder":1,"removeOlderPoints":"10","removeOlderUnit":"86400","cutout":0,"useOneColor":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"outputs":1,"x":1010,"y":340,"wires":[[]]},{"id":"c07f00b3.b5976","type":"debug","z":"686d65d5.97d88c","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":870,"y":400,"wires":[]},{"id":"f467e883.c585e8","type":"function","z":"686d65d5.97d88c","name":"","func":"tab=msg.payload;\nvar toSend=[{\n\"series\": [\"A\"],\n\"data\": [[]],\n\"labels\": [\"\"]\n}];\nvar i;\nfor (i = 0; i < tab.length; i++) { \n //toSend={topic:\"temperature\", payload : tab[i].temperatura, timestamp : tab[i].time }\n toSend[0][\"data\"][0].push({\n x : tab[i].time,\n y : tab[i].temperatura\n });\n}\n\nvar test=[{\n\"series\": [\"A\"],\n\"data\": [\n [{ \"x\": tab[1].time, \"y\": 5 },\n { \"x\": tab[2].time, \"y\": 4 },\n { \"x\": tab[3].time, \"y\": 2 }\n ]\n],\n\"labels\": [\"\"]\n}];\n\nmsg.payload=toSend;\n\nreturn msg;","outputs":1,"noerr":0,"x":830,"y":340,"wires":[["e7603544.632d58"]]},{"id":"7ea6c487.0b487c","type":"function","z":"686d65d5.97d88c","name":"","func":"var displayPoint = msg.payload;\n\nmsg.topic=\"SELECT `temperatura`, `umidita`,`time` FROM `seedHydroTemp` ORDER BY `time` DESC LIMIT \"+displayPoint+\";\"\nreturn msg;","outputs":1,"noerr":0,"x":490,"y":340,"wires":[["508f7e0f.bd6fc"]]},{"id":"3b6a355d.b7f35a","type":"ui_numeric","z":"686d65d5.97d88c","name":"","label":"Numero de data ","tooltip":"","group":"57b0e2d1.c7720c","order":2,"width":0,"height":0,"passthru":true,"topic":"","format":"{{value}}","min":0,"max":"200","step":"10","x":300,"y":340,"wires":[["7ea6c487.0b487c"]]},{"id":"42772348.76788c","type":"function","z":"686d65d5.97d88c","name":"DB filter wtrLvl","func":"var wtrLvl;\n\n\n\n\nif (msg.topic ==\"stationMKR/wtrlvl\")\n{\n wtrLvl = msg.payload;\n msg.topic =\"INSERT INTO `seedWaterCycle` (`id`, `waterLevel`) VALUES (NULL, '\"+wtrLvl+\"');\"\n return msg;\n}\n\n\n","outputs":1,"noerr":0,"x":440,"y":120,"wires":[["4b29a512.6fd13c"]]},{"id":"a18de386.c0b6d","type":"debug","z":"686d65d5.97d88c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":870,"y":60,"wires":[]},{"id":"508f7e0f.bd6fc","type":"mysql","z":"686d65d5.97d88c","mydb":"8bdd4b2a.669e28","name":"","x":660,"y":340,"wires":[["f467e883.c585e8","52e1065e.00da68","c07f00b3.b5976"]]},{"id":"6254b9fc.d87558","type":"ui_chart","z":"686d65d5.97d88c","name":"","group":"8a6026b4.4f4538","order":2,"width":0,"height":0,"label":"chart umidita","chartType":"line","legend":"false","xformat":"auto","interpolate":"linear","nodata":"","dot":false,"ymin":"","ymax":"","removeOlder":1,"removeOlderPoints":"10","removeOlderUnit":"86400","cutout":0,"useOneColor":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"outputs":1,"x":990,"y":460,"wires":[[]]},{"id":"1e1c5c38.f17924","type":"debug","z":"686d65d5.97d88c","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":990,"y":500,"wires":[]},{"id":"52e1065e.00da68","type":"function","z":"686d65d5.97d88c","name":"","func":"tab=msg.payload;\nvar toSend=[{\n\"series\": [\"A\"],\n\"data\": [[]],\n\"labels\": [\"\"]\n}];\nvar i;\nfor (i = 0; i < tab.length; i++) { \n //toSend={topic:\"temperature\", payload : tab[i].temperatura, timestamp : tab[i].time }\n toSend[0][\"data\"][0].push({\n x : tab[i].time,\n y : tab[i].umidita\n });\n}\n\nvar test=[{\n\"series\": [\"A\"],\n\"data\": [\n [{ \"x\": tab[1].time, \"y\": 5 },\n { \"x\": tab[2].time, \"y\": 4 },\n { \"x\": tab[3].time, \"y\": 2 }\n ]\n],\n\"labels\": [\"\"]\n}];\n\nmsg.payload=toSend;\n\nreturn msg;","outputs":1,"noerr":0,"x":850,"y":480,"wires":[["6254b9fc.d87558","1e1c5c38.f17924"]]},{"id":"2d74770f.1fa708","type":"ui_numeric","z":"686d65d5.97d88c","name":"","label":"Tempo de aqua ON en secunda","tooltip":"","group":"57b0e2d1.c7720c","order":2,"width":0,"height":0,"passthru":true,"topic":"","format":"{{value}}","min":0,"max":"20","step":"1","x":730,"y":180,"wires":[["b8650786.59d888","3bf10796.a863f8"]]},{"id":"3bf10796.a863f8","type":"debug","z":"686d65d5.97d88c","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":990,"y":120,"wires":[]},{"id":"d647a94e.68cab8","type":"ui_numeric","z":"686d65d5.97d88c","name":"","label":"Tempo de loop ON en minuta","tooltip":"","group":"57b0e2d1.c7720c","order":2,"width":0,"height":0,"passthru":true,"topic":"","format":"{{value}}","min":0,"max":"360","step":"1","x":600,"y":260,"wires":[["730e92ef.36293c"]]},{"id":"730e92ef.36293c","type":"mqtt out","z":"686d65d5.97d88c","name":"Pum command","topic":"stationMKR/loopcmd","qos":"1","retain":"true","broker":"442d1ac5.343774","x":920,"y":260,"wires":[]},{"id":"442d1ac5.343774","type":"mqtt-broker","z":"","name":"raspibroker","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"8bdd4b2a.669e28","type":"MySQLdatabase","z":"","host":"127.0.0.1","port":"3306","db":"DB_OrtoHydro","tz":""},{"id":"8a6026b4.4f4538","type":"ui_group","z":"","name":"GraphicOrto","tab":"8aa5db.abbcaa28","disp":true,"width":"6","collapse":false},{"id":"57b0e2d1.c7720c","type":"ui_group","z":"","name":"Orto Command","tab":"8aa5db.abbcaa28","disp":true,"width":"6","collapse":false},{"id":"8aa5db.abbcaa28","type":"ui_tab","z":"","name":"notizie orto-hydro","icon":"dashboard","order":1,"disabled":false,"hidden":false}]
22 changes: 22 additions & 0 deletions source/_static/OrtoCity-v2/boot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import machine
from network import WLAN
import pycom

pycom.heartbeat(False)
pycom.rgbled(0x7f0000)

if (False):
wlan = WLAN() # get current object, without changing the mode

if machine.reset_cause() != machine.SOFT_RESET:
wlan.init(mode=WLAN.STA)
# configuration below MUST match your home router settings!!
wlan.ifconfig(config=('192.168.0.111', '255.255.255.0', '192.168.0.1', '8.8.8.8'))

if not wlan.isconnected():
# change the line below to match your network ssid, security and password
wlan.connect('plumake', auth=(WLAN.WPA2, 'wiplumfi13'), timeout=5000)
while not wlan.isconnected():
machine.idle() # save power while waiting


0 comments on commit df91b71

Please sign in to comment.