Skip to content

Instantly share code, notes, and snippets.

@unixweb
Created May 12, 2018 16:36
Show Gist options
  • Save unixweb/f915465c6b785480ffac048b0bc12897 to your computer and use it in GitHub Desktop.
Save unixweb/f915465c6b785480ffac048b0bc12897 to your computer and use it in GitHub Desktop.
Octopus first steps flow.json = for Node-Red / octopus-start.ino = for Arduino IDE
[{"id":"7b3f4073.b32038","type":"tab","label":"GUI Octopus","disabled":false,"info":""},{"id":"dc513135.edb458","type":"mqtt in","z":"7b3f4073.b32038","name":"Temperature BME280","topic":"bme280/Temperature","qos":"2","broker":"279e0107.125de6","x":140,"y":80,"wires":[["8400de8a.3268","a177ec04.34a648"]]},{"id":"b9589d65.e88848","type":"ui_gauge","z":"7b3f4073.b32038","name":"","group":"1ee64821.04fba","order":1,"width":0,"height":0,"gtype":"gage","title":"Temperature BME280","label":"° Celsius","format":"{{value}}","min":0,"max":"50","colors":["#00b500","#e6e600","#ca3838"],"seg1":"30","seg2":"31","x":740,"y":80,"wires":[]},{"id":"91c5dd29.7d6be","type":"ui_chart","z":"7b3f4073.b32038","name":"","group":"1ee64821.04fba","order":4,"width":0,"height":0,"label":"Temperature BME280","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"","ymax":"","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"x":740,"y":120,"wires":[[],[]]},{"id":"ffb20ece.247028","type":"ui_gauge","z":"7b3f4073.b32038","name":"","group":"1ee64821.04fba","order":2,"width":0,"height":0,"gtype":"gage","title":"Pressure BME280","label":"hPa","format":"{{value}}","min":"900","max":"1000","colors":["#00b500","#e6e600","#ca3838"],"seg1":"998","seg2":"999","x":730,"y":180,"wires":[]},{"id":"b8067ebf.84cee8","type":"mqtt in","z":"7b3f4073.b32038","name":"Pressure BME280","topic":"bme280/Pressure","qos":"2","broker":"279e0107.125de6","x":130,"y":180,"wires":[["edcc89ea.777d48","f31339dc.65e318"]]},{"id":"1241be14.1623e2","type":"ui_chart","z":"7b3f4073.b32038","name":"","group":"1ee64821.04fba","order":5,"width":0,"height":0,"label":"Pressure BME280","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"","ymax":"","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"x":730,"y":220,"wires":[[],[]]},{"id":"fa8bfbb3.e737f8","type":"ui_gauge","z":"7b3f4073.b32038","name":"","group":"1ee64821.04fba","order":3,"width":0,"height":0,"gtype":"gage","title":"Humidity BME280","label":"%","format":"{{value}}","min":0,"max":"100","colors":["#00b500","#e6e600","#ca3838"],"seg1":"98","seg2":"99","x":730,"y":280,"wires":[]},{"id":"d5e8c8bd.4307f","type":"mqtt in","z":"7b3f4073.b32038","name":"Humidity BME280","topic":"bme280/Humidity","qos":"2","broker":"279e0107.125de6","x":120,"y":280,"wires":[["a8e4c80c.5c0a2","3becb4c4.a7bf64"]]},{"id":"5c0aea64.cb20ac","type":"ui_gauge","z":"7b3f4073.b32038","name":"","group":"30f4a047.e3c3c8","order":1,"width":0,"height":0,"gtype":"gage","title":"Temperature BME680","label":"° Celsius","format":"{{value}}","min":0,"max":"50","colors":["#00b500","#e6e600","#ca3838"],"seg1":"30","seg2":"31","x":740,"y":400,"wires":[]},{"id":"271c6d1f.fbc05a","type":"mqtt in","z":"7b3f4073.b32038","name":"Temperature BME680","topic":"bme680/Temperature","qos":"2","broker":"279e0107.125de6","x":140,"y":400,"wires":[["3de8b4b8.9acc14","daed1cf9.0f573"]]},{"id":"c4414a0.e405a38","type":"ui_gauge","z":"7b3f4073.b32038","name":"","group":"30f4a047.e3c3c8","order":2,"width":0,"height":0,"gtype":"gage","title":"Pressure BME680","label":"hPa","format":"{{value}}","min":"900","max":"1000","colors":["#00b500","#e6e600","#ca3838"],"seg1":"995","seg2":"996","x":730,"y":500,"wires":[]},{"id":"5feb2aeb.93e88c","type":"mqtt in","z":"7b3f4073.b32038","name":"Pressure BME680","topic":"bme680/Pressure","qos":"2","broker":"279e0107.125de6","x":130,"y":500,"wires":[["59a10ac2.4665cc","a48035be.de246"]]},{"id":"82ace125.96c218","type":"ui_chart","z":"7b3f4073.b32038","name":"","group":"30f4a047.e3c3c8","order":5,"width":0,"height":0,"label":"Pressure BME680","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"","ymax":"","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"x":730,"y":540,"wires":[[],[]]},{"id":"ad9d4d7a.bd30f","type":"ui_gauge","z":"7b3f4073.b32038","name":"","group":"30f4a047.e3c3c8","order":3,"width":0,"height":0,"gtype":"gage","title":"Humidity BME680","label":"%","format":"{{value}}","min":0,"max":"100","colors":["#00b500","#e6e600","#ca3838"],"seg1":"98","seg2":"99","x":730,"y":600,"wires":[]},{"id":"de5c342e.f737f8","type":"mqtt in","z":"7b3f4073.b32038","name":"Humidity BME680","topic":"bme680/Humidity","qos":"2","broker":"279e0107.125de6","x":120,"y":600,"wires":[["821e2a18.2573f","4d200311.ee8bbc"]]},{"id":"ef4b3a68.a738b8","type":"ui_chart","z":"7b3f4073.b32038","name":"","group":"30f4a047.e3c3c8","order":6,"width":0,"height":0,"label":"Humidity BME680","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"","ymax":"","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"x":730,"y":640,"wires":[[],[]]},{"id":"24ecf93.901af86","type":"ui_chart","z":"7b3f4073.b32038","name":"","group":"1ee64821.04fba","order":6,"width":0,"height":0,"label":"Humidity BME280","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"","ymax":"","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"x":730,"y":320,"wires":[[],[]]},{"id":"3b6a3a89.55da2e","type":"ui_chart","z":"7b3f4073.b32038","name":"","group":"30f4a047.e3c3c8","order":4,"width":0,"height":0,"label":"Temperature BME680","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"","ymax":"","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"x":740,"y":440,"wires":[[],[]]},{"id":"8400de8a.3268","type":"function","z":"7b3f4073.b32038","name":"custom function 1","func":"// declare place holder variables\nvar originalval = msg.payload;\nvar value = \"\";\n\n\n// convert string of originalval to float with 1 decimal place\n// run originalval thru a simple minus operation to form the 'temp' number\nvalue = parseFloat(originalval).toFixed(1) - 1;\n\n// output the originalval after deduction \nmsg.payload = value;\n\n\nreturn msg;","outputs":1,"noerr":0,"x":450,"y":80,"wires":[["b9589d65.e88848"]]},{"id":"a177ec04.34a648","type":"function","z":"7b3f4073.b32038","name":"custom function","func":"// declare place holder variables\nvar originalval = msg.payload;\nvar temp = \"\";\n\n\n// convert string of originalval to float with 1 decimal place\n// run originalval thru a simple minus operation to form the 'temp' number\ntemp = parseFloat(originalval).toFixed(1) - 1;\n\n// output the originalval after deduction \nmsg.payload = temp;\n\n\nreturn msg;","outputs":1,"noerr":0,"x":440,"y":120,"wires":[["91c5dd29.7d6be"]]},{"id":"42f97d8d.81b57c","type":"function","z":"7b3f4073.b32038","name":"custom function 2","func":"// declare place holder variables\nvar originalval = msg.payload;\nvar value = \"\";\n\n\n// convert string of originalval to float with 1 decimal place\n// run originalval thru a simple minus operation to form the 'temp' number\nvalue = parseFloat(originalval).toFixed(0) - 1;\n\n// output the originalval after deduction \nmsg.payload = value;\n\n\nreturn msg;","outputs":1,"noerr":0,"x":450,"y":120,"wires":[[]]},{"id":"edcc89ea.777d48","type":"function","z":"7b3f4073.b32038","name":"custom function 1","func":"// declare place holder variables\nvar originalval = msg.payload;\nvar value = \"\";\n\n\n// convert string of originalval to float with 1 decimal place\n// run originalval thru a simple minus operation to form the 'temp' number\nvalue = parseFloat(originalval).toFixed(1) - 1;\n\n// output the originalval after deduction \nmsg.payload = value;\n\n\nreturn msg;","outputs":1,"noerr":0,"x":470,"y":180,"wires":[["ffb20ece.247028"]]},{"id":"f31339dc.65e318","type":"function","z":"7b3f4073.b32038","name":"custom function 2","func":"// declare place holder variables\nvar originalval = msg.payload;\nvar value = \"\";\n\n\n// convert string of originalval to float with 1 decimal place\n// run originalval thru a simple minus operation to form the 'temp' number\nvalue = parseFloat(originalval).toFixed(0) - 1;\n\n// output the originalval after deduction \nmsg.payload = value;\n\n\nreturn msg;","outputs":1,"noerr":0,"x":470,"y":220,"wires":[["1241be14.1623e2"]]},{"id":"a8e4c80c.5c0a2","type":"function","z":"7b3f4073.b32038","name":"custom function 2","func":"// declare place holder variables\nvar originalval = msg.payload;\nvar value = \"\";\n\n\n// convert string of originalval to float with 1 decimal place\n// run originalval thru a simple minus operation to form the 'temp' number\nvalue = parseFloat(originalval).toFixed(0) - 1;\n\n// output the originalval after deduction \nmsg.payload = value;\n\n\nreturn msg;","outputs":1,"noerr":0,"x":470,"y":280,"wires":[["fa8bfbb3.e737f8"]]},{"id":"3becb4c4.a7bf64","type":"function","z":"7b3f4073.b32038","name":"custom function 2","func":"// declare place holder variables\nvar originalval = msg.payload;\nvar value = \"\";\n\n\n// convert string of originalval to float with 1 decimal place\n// run originalval thru a simple minus operation to form the 'temp' number\nvalue = parseFloat(originalval).toFixed(0) - 1;\n\n// output the originalval after deduction \nmsg.payload = value;\n\n\nreturn msg;","outputs":1,"noerr":0,"x":470,"y":320,"wires":[["24ecf93.901af86"]]},{"id":"3de8b4b8.9acc14","type":"function","z":"7b3f4073.b32038","name":"custom function 1","func":"// declare place holder variables\nvar originalval = msg.payload;\nvar value = \"\";\n\n\n// convert string of originalval to float with 1 decimal place\n// run originalval thru a simple minus operation to form the 'temp' number\nvalue = parseFloat(originalval).toFixed(1) - 1;\n\n// output the originalval after deduction \nmsg.payload = value;\n\n\nreturn msg;","outputs":1,"noerr":0,"x":450,"y":400,"wires":[["5c0aea64.cb20ac"]]},{"id":"daed1cf9.0f573","type":"function","z":"7b3f4073.b32038","name":"custom function 2","func":"var originalval = msg.payload;\nvar value = \"\";\nvalue = parseFloat(originalval).toFixed(1) - 1;\nmsg.payload = value;\nreturn msg;","outputs":1,"noerr":0,"x":450,"y":440,"wires":[["3b6a3a89.55da2e"]]},{"id":"59a10ac2.4665cc","type":"function","z":"7b3f4073.b32038","name":"custom function 1","func":"// declare place holder variables\nvar originalval = msg.payload;\nvar value = \"\";\n\n\n// convert string of originalval to float with 1 decimal place\n// run originalval thru a simple minus operation to form the 'temp' number\nvalue = parseFloat(originalval).toFixed(0) - 1;\n\n// output the originalval after deduction \nmsg.payload = value;\n\n\nreturn msg;","outputs":1,"noerr":0,"x":450,"y":500,"wires":[["c4414a0.e405a38"]]},{"id":"a48035be.de246","type":"function","z":"7b3f4073.b32038","name":"custom function 2","func":"// declare place holder variables\nvar originalval = msg.payload;\nvar value = \"\";\n\n\n// convert string of originalval to float with 1 decimal place\n// run originalval thru a simple minus operation to form the 'temp' number\nvalue = parseFloat(originalval).toFixed(0) - 1;\n\n// output the originalval after deduction \nmsg.payload = value;\n\n\nreturn msg;","outputs":1,"noerr":0,"x":450,"y":540,"wires":[["82ace125.96c218"]]},{"id":"821e2a18.2573f","type":"function","z":"7b3f4073.b32038","name":"custom function 2","func":"// declare place holder variables\nvar originalval = msg.payload;\nvar value = \"\";\n\n\n// convert string of originalval to float with 1 decimal place\n// run originalval thru a simple minus operation to form the 'temp' number\nvalue = parseFloat(originalval).toFixed(0) - 1;\n\n// output the originalval after deduction \nmsg.payload = value;\n\n\nreturn msg;","outputs":1,"noerr":0,"x":450,"y":600,"wires":[["ad9d4d7a.bd30f"]]},{"id":"4d200311.ee8bbc","type":"function","z":"7b3f4073.b32038","name":"custom function 2","func":"// declare place holder variables\nvar originalval = msg.payload;\nvar value = \"\";\n\n\n// convert string of originalval to float with 1 decimal place\n// run originalval thru a simple minus operation to form the 'temp' number\nvalue = parseFloat(originalval).toFixed(0) - 1;\n\n// output the originalval after deduction \nmsg.payload = value;\n\n\nreturn msg;","outputs":1,"noerr":0,"x":450,"y":640,"wires":[["ef4b3a68.a738b8"]]},{"id":"279e0107.125de6","type":"mqtt-broker","z":"","broker":"mqtt.unixweb.de","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"willTopic":"","willQos":"0","willPayload":"","birthTopic":"","birthQos":"0","birthPayload":""},{"id":"1ee64821.04fba","type":"ui_group","z":"","name":"BME280","tab":"4da6b454.0acb3c","order":3,"disp":false,"width":"6","collapse":false},{"id":"30f4a047.e3c3c8","type":"ui_group","z":"","name":"BME680","tab":"4da6b454.0acb3c","order":2,"disp":false,"width":"6","collapse":false},{"id":"4da6b454.0acb3c","type":"ui_tab","z":"","name":"Octopus","icon":"dashboard"}]
#include <ESP8266WiFi.h>
#include <PubSubClient.h>
#include <Adafruit_NeoPixel.h>
#include <SparkFunBME280.h>
#include <Wire.h>
#include <Adafruit_BME680.h>
String matrixausgabe_text = " "; // Ausgabetext als globale Variable
volatile int matrixausgabe_index = 0;// aktuelle Position in Matrix
//-------------- definition mqtt-object ueber WiFi
WiFiClient espClient;
PubSubClient mqttclient(espClient);
//--------- list of mqtt callback functions
#define MAX_MQTT_SUB 10 // maximal 10 subscriptions erlaubt
typedef void (*mqtthandle) (byte*,unsigned int);
typedef struct { // Typdeklaration Callback
String topic; // mqtt-topic
mqtthandle fun; // callback function
}
subscribe_type;
subscribe_type mqtt_sub[MAX_MQTT_SUB];
int mqtt_sub_count=0;
String MQTT_Rx_Payload = "" ;
//--------- mqtt callback function
void mqttcallback(char* to, byte* pay, unsigned int len) {
String topic = String(to);
String payload = String((char*)pay);
MQTT_Rx_Payload=payload.substring(0,len);
Serial.println("\ncallback topic:" + topic + ", payload:" + MQTT_Rx_Payload);
for (int i=0;i<mqtt_sub_count;i++) { // durchsuche alle subscriptions, bis topic passt
if (topic==mqtt_sub[i].topic)
mqtt_sub[i].fun(pay,len); // Aufruf der richtigen callback-Funktion
}
}
//------------ reconnect mqtt-client
void mqttreconnect() { // Loop until we're reconnected
if (!mqttclient.connected()) {
while (!mqttclient.connected()) {
Serial.print("Attempting MQTT connection...");
if (mqttclient.connect("IoTHackathon" , "user", "passwort" )) {
Serial.println("connected");
for (int i=0;i<mqtt_sub_count;i++) { // subscribe topic
mqttclient.subscribe(mqtt_sub[i].topic.c_str());
Serial.println("\nsubscribe");
Serial.print(mqtt_sub[i].topic);
}
}
else {
Serial.print("failed, rc=");
Serial.print(mqttclient.state());
Serial.println(" try again in 5 seconds");
delay(5000);
}
}
}
else {
mqttclient.loop();
}
}
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(2,13,NEO_GRBW + NEO_KHZ800);
// Marshall Tylor@sparkfun https://github.com/sparkfun/SparkFun_BME280_Arduino_Library
BME280 boschBME280; // Objekt Bosch Umweltsensor
// BME680 Lib written by Limor Fried & Kevin Townsend for Adafruit Industries, http://www.adafruit.com/products/3660
Adafruit_BME680 boschBME680; // Objekt Bosch Umweltsensor
extern "C" { // zur Nutzung der speziellen ESP-Befehle wie Deep Sleep
#include "user_interface.h"
}
void setup(){ // Einmalige Initialisierung
Serial.begin(115200);
//----------------------------------MQTT-Client
mqttclient.setServer("mqtt.unixweb.de", 1883);
mqttclient.setCallback(mqttcallback);
pixels.begin();//-------------- Initialisierung Neopixel
delay(1);
pixels.show();
pixels.setPixelColor(0,0,0,0); // alle aus
pixels.setPixelColor(1,0,0,0);
pixels.show(); // und anzeigen
Wire.begin(); // ---- Initialisiere den I2C-Bus
if (Wire.status() != I2C_OK) Serial.println("Something wrong with I2C");
boschBME280.settings.runMode = 3; // Normal Mode
boschBME280.settings.tempOverSample = 4;
boschBME280.settings.pressOverSample = 4;
boschBME280.settings.humidOverSample = 4;
boschBME280.begin();
if (!boschBME680.begin(118)) {
Serial.println("Failed to communicate BME680");
while (1) {
delay(1);
};
}
// Set up Bosch BME 680
boschBME680.setTemperatureOversampling(BME680_OS_8X);
boschBME680.setHumidityOversampling(BME680_OS_2X);
boschBME680.setPressureOversampling(BME680_OS_4X);
boschBME680.setIIRFilterSize(BME680_FILTER_SIZE_3);
boschBME680.setGasHeater(320, 150); // 320*C for 150 ms
//------------ WLAN initialisieren
WiFi.persistent(false);
WiFi.mode(WIFI_STA);
delay(100);
Serial.print ("\nWLAN connect to:");
Serial.print("Lisberg-2");
WiFi.begin("Lisberg-2","23462716825789145613");
while (WiFi.status() != WL_CONNECTED) { // Warte bis Verbindung steht
delay(500);
Serial.print(".");
};
Serial.println ("\nconnected, meine IP:"+ WiFi.localIP().toString());
matrixausgabe_text = " Meine IP:" + WiFi.localIP().toString();
matrixausgabe_index=0;
}
void loop() { // Kontinuierliche Wiederholung
pixels.setPixelColor(0,30&0x3F,0&0x3F,0&0x3F);
pixels.show();
pixels.setPixelColor(1,30&0x3F,0&0x3F,0&0x3F);
pixels.show();
mqttreconnect();
{
String pay=String(String(boschBME280.readTempC()));
mqttclient.publish("bme280/Temperature",pay.c_str());
Serial.print("\nmqtt publish: ");
Serial.print(pay);
};
mqttreconnect();
{
String pay=String(String(boschBME280.readFloatPressure()/100.));
mqttclient.publish("bme280/Pressure",pay.c_str());
Serial.print("\nmqtt publish: ");
Serial.print(pay);
};
mqttreconnect();
{
String pay=String(String(boschBME280.readFloatHumidity()));
mqttclient.publish("bme280/Humidity",pay.c_str());
Serial.print("\nmqtt publish: ");
Serial.print(pay);
};
mqttreconnect();
{
String pay=String(String(boschBME680.readTemperature()));
mqttclient.publish("bme680/Temperature",pay.c_str());
Serial.print("\nmqtt publish: ");
Serial.print(pay);
};
mqttreconnect();
{
String pay=String(String(boschBME680.readPressure()/100.));
mqttclient.publish("bme680/Pressure",pay.c_str());
Serial.print("\nmqtt publish: ");
Serial.print(pay);
};
mqttreconnect();
{
String pay=String(String(boschBME680.readHumidity()));
mqttclient.publish("bme680/Humidity",pay.c_str());
Serial.print("\nmqtt publish: ");
Serial.print(pay);
};
delay( 1000 );
pixels.setPixelColor(0,0&0x3F,0&0x3F,30&0x3F);
pixels.show();
pixels.setPixelColor(1,0&0x3F,0&0x3F,30&0x3F);
pixels.show();
delay( 1000 );
pixels.setPixelColor(0,0&0x3F,30&0x3F,0&0x3F);
pixels.show();
pixels.setPixelColor(1,0&0x3F,30&0x3F,0&0x3F);
pixels.show();
delay( 5000 );
pixels.setPixelColor(0,0&0x3F,0&0x3F,0&0x3F);
pixels.show();
pixels.setPixelColor(1,0&0x3F,0&0x3F,0&0x3F);
pixels.show();
ESP.deepSleep( (long)600000*1000UL,WAKE_RF_DEFAULT);//Tiefschlaf, danach Reset und von vorn
}
@unixweb
Copy link
Author

unixweb commented May 12, 2018

1.) Upload first the octopus-start.ino to octopus board with Ardunino IDE
2.) Import flow.json into the Node-Red
3.) Start the Dashboard with http://:1880/ui

img_20180509_112508_017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment