From a444f87744033ff560a5456d4a4eefd572d0fc52 Mon Sep 17 00:00:00 2001 From: Joachim Hummel Date: Thu, 2 Mar 2023 21:50:08 +0000 Subject: [PATCH] Added new sketch and edit Readme --- CO2-Ampel-MQTT-BME680-SCD30-7Segement.ino | 298 ++++++++++++++++++++++ README.md | 6 +- 2 files changed, 301 insertions(+), 3 deletions(-) create mode 100644 CO2-Ampel-MQTT-BME680-SCD30-7Segement.ino diff --git a/CO2-Ampel-MQTT-BME680-SCD30-7Segement.ino b/CO2-Ampel-MQTT-BME680-SCD30-7Segement.ino new file mode 100644 index 0000000..4ec0496 --- /dev/null +++ b/CO2-Ampel-MQTT-BME680-SCD30-7Segement.ino @@ -0,0 +1,298 @@ +/* Disclaimer IoT-Werkstatt CC 4.0 BY NC SA + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For Ardublock see the + GNU General Public License for more details. */ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +String matrixausgabe_text = " "; // Ausgabetext als globale Variable + +volatile int matrixausgabe_index = 0;// aktuelle Position in Matrix + +IPAddress myOwnIP; // ownIP for mDNS + +//-------------- 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