From 730189f29429d0983a4fb90b8ec72039a7cc47e4 Mon Sep 17 00:00:00 2001 From: andy Date: Tue, 31 Mar 2020 23:09:11 +0200 Subject: [PATCH] running but not connecting right now --- .project | 4 +- .settings/language.settings.xml | 2 +- .settings/org.eclipse.cdt.core.prefs | 70 ++++++++++++++++----- BME280MTTQ.ino | 94 ++++++++++++++-------------- spec.d | 4 +- 5 files changed, 104 insertions(+), 70 deletions(-) diff --git a/.project b/.project index 7a504b4..7c812a4 100644 --- a/.project +++ b/.project @@ -39,12 +39,12 @@ core/variant 2 - ECLIPSE_HOME/arduinoPlugin/packages/arduino/hardware/avr/1.8.2/variants/eightanaloginputs + ECLIPSE_HOME/arduinoPlugin/packages/arduino/hardware/avr/1.8.2/variants/mega libraries/BME280 2 - ECLIPSE_HOME/arduinoPlugin/libraries/BME280/2.3.0 + C:/Users/Andy.I4A/Documents/Arduino/libraries/BME280 libraries/Ethernet diff --git a/.settings/language.settings.xml b/.settings/language.settings.xml index 582925f..4553b21 100644 --- a/.settings/language.settings.xml +++ b/.settings/language.settings.xml @@ -4,7 +4,7 @@ - + diff --git a/.settings/org.eclipse.cdt.core.prefs b/.settings/org.eclipse.cdt.core.prefs index ca76584..2d02f41 100644 --- a/.settings/org.eclipse.cdt.core.prefs +++ b/.settings/org.eclipse.cdt.core.prefs @@ -13,10 +13,10 @@ environment/project/io.sloeber.core.toolChain.release.1051055115/A.BOOTLOADER.EX environment/project/io.sloeber.core.toolChain.release.1051055115/A.BOOTLOADER.EXTENDED_FUSES/value=0xFD environment/project/io.sloeber.core.toolChain.release.1051055115/A.BOOTLOADER.FILE/delimiter=; environment/project/io.sloeber.core.toolChain.release.1051055115/A.BOOTLOADER.FILE/operation=replace -environment/project/io.sloeber.core.toolChain.release.1051055115/A.BOOTLOADER.FILE/value=atmega/ATmegaBOOT_168_atmega328.hex +environment/project/io.sloeber.core.toolChain.release.1051055115/A.BOOTLOADER.FILE/value=stk500v2/stk500boot_v2_mega2560.hex environment/project/io.sloeber.core.toolChain.release.1051055115/A.BOOTLOADER.HIGH_FUSES/delimiter=; environment/project/io.sloeber.core.toolChain.release.1051055115/A.BOOTLOADER.HIGH_FUSES/operation=replace -environment/project/io.sloeber.core.toolChain.release.1051055115/A.BOOTLOADER.HIGH_FUSES/value=0xDA +environment/project/io.sloeber.core.toolChain.release.1051055115/A.BOOTLOADER.HIGH_FUSES/value=0xD8 environment/project/io.sloeber.core.toolChain.release.1051055115/A.BOOTLOADER.LOCK_BITS/delimiter=; environment/project/io.sloeber.core.toolChain.release.1051055115/A.BOOTLOADER.LOCK_BITS/operation=replace environment/project/io.sloeber.core.toolChain.release.1051055115/A.BOOTLOADER.LOCK_BITS/value=0x0F @@ -34,7 +34,7 @@ environment/project/io.sloeber.core.toolChain.release.1051055115/A.BUILD.ARCH/op environment/project/io.sloeber.core.toolChain.release.1051055115/A.BUILD.ARCH/value=AVR environment/project/io.sloeber.core.toolChain.release.1051055115/A.BUILD.BOARD/delimiter=; environment/project/io.sloeber.core.toolChain.release.1051055115/A.BUILD.BOARD/operation=replace -environment/project/io.sloeber.core.toolChain.release.1051055115/A.BUILD.BOARD/value=AVR_NANO +environment/project/io.sloeber.core.toolChain.release.1051055115/A.BUILD.BOARD/value=AVR_MEGA2560 environment/project/io.sloeber.core.toolChain.release.1051055115/A.BUILD.CORE.PATH/delimiter=; environment/project/io.sloeber.core.toolChain.release.1051055115/A.BUILD.CORE.PATH/operation=replace environment/project/io.sloeber.core.toolChain.release.1051055115/A.BUILD.CORE.PATH/value=C\:\\Sloeber\\arduinoPlugin\\packages\\arduino\\hardware\\avr\\1.8.2\\cores\\arduino @@ -49,7 +49,7 @@ environment/project/io.sloeber.core.toolChain.release.1051055115/A.BUILD.F_CPU/o environment/project/io.sloeber.core.toolChain.release.1051055115/A.BUILD.F_CPU/value=16000000L environment/project/io.sloeber.core.toolChain.release.1051055115/A.BUILD.MCU/delimiter=; environment/project/io.sloeber.core.toolChain.release.1051055115/A.BUILD.MCU/operation=replace -environment/project/io.sloeber.core.toolChain.release.1051055115/A.BUILD.MCU/value=atmega328p +environment/project/io.sloeber.core.toolChain.release.1051055115/A.BUILD.MCU/value=atmega2560 environment/project/io.sloeber.core.toolChain.release.1051055115/A.BUILD.PATH/delimiter=; environment/project/io.sloeber.core.toolChain.release.1051055115/A.BUILD.PATH/operation=replace environment/project/io.sloeber.core.toolChain.release.1051055115/A.BUILD.PATH/value=${ProjDirPath}/${ConfigName} @@ -67,10 +67,10 @@ environment/project/io.sloeber.core.toolChain.release.1051055115/A.BUILD.USB_MAN environment/project/io.sloeber.core.toolChain.release.1051055115/A.BUILD.USB_MANUFACTURER/value=\\"Unknown\\" environment/project/io.sloeber.core.toolChain.release.1051055115/A.BUILD.VARIANT.PATH/delimiter=; environment/project/io.sloeber.core.toolChain.release.1051055115/A.BUILD.VARIANT.PATH/operation=replace -environment/project/io.sloeber.core.toolChain.release.1051055115/A.BUILD.VARIANT.PATH/value=C\:\\Sloeber\\arduinoPlugin\\packages\\arduino\\hardware\\avr\\1.8.2\\variants\\eightanaloginputs +environment/project/io.sloeber.core.toolChain.release.1051055115/A.BUILD.VARIANT.PATH/value=C\:\\Sloeber\\arduinoPlugin\\packages\\arduino\\hardware\\avr\\1.8.2\\variants\\mega environment/project/io.sloeber.core.toolChain.release.1051055115/A.BUILD.VARIANT/delimiter=; environment/project/io.sloeber.core.toolChain.release.1051055115/A.BUILD.VARIANT/operation=replace -environment/project/io.sloeber.core.toolChain.release.1051055115/A.BUILD.VARIANT/value=eightanaloginputs +environment/project/io.sloeber.core.toolChain.release.1051055115/A.BUILD.VARIANT/value=mega environment/project/io.sloeber.core.toolChain.release.1051055115/A.COMPILER.AR.CMD/delimiter=; environment/project/io.sloeber.core.toolChain.release.1051055115/A.COMPILER.AR.CMD/operation=replace environment/project/io.sloeber.core.toolChain.release.1051055115/A.COMPILER.AR.CMD/value=avr-gcc-ar @@ -91,7 +91,7 @@ environment/project/io.sloeber.core.toolChain.release.1051055115/A.COMPILER.C.EL environment/project/io.sloeber.core.toolChain.release.1051055115/A.COMPILER.C.ELF.EXTRA_FLAGS/value= environment/project/io.sloeber.core.toolChain.release.1051055115/A.COMPILER.C.ELF.FLAGS/delimiter=; environment/project/io.sloeber.core.toolChain.release.1051055115/A.COMPILER.C.ELF.FLAGS/operation=replace -environment/project/io.sloeber.core.toolChain.release.1051055115/A.COMPILER.C.ELF.FLAGS/value=${A.COMPILER.WARNING_FLAGS} -Os -g -flto -fuse-linker-plugin -Wl,--gc-sections +environment/project/io.sloeber.core.toolChain.release.1051055115/A.COMPILER.C.ELF.FLAGS/value=${A.COMPILER.WARNING_FLAGS} -Os -Wl,--gc-sections,--relax environment/project/io.sloeber.core.toolChain.release.1051055115/A.COMPILER.C.EXTRA_FLAGS/delimiter=; environment/project/io.sloeber.core.toolChain.release.1051055115/A.COMPILER.C.EXTRA_FLAGS/operation=replace environment/project/io.sloeber.core.toolChain.release.1051055115/A.COMPILER.C.EXTRA_FLAGS/value= @@ -160,10 +160,28 @@ environment/project/io.sloeber.core.toolChain.release.1051055115/A.ESP8266.NETWO environment/project/io.sloeber.core.toolChain.release.1051055115/A.ESP8266.NETWORK.UPLOAD.TOOL/value=esp8266OTA environment/project/io.sloeber.core.toolChain.release.1051055115/A.NAME/delimiter=; environment/project/io.sloeber.core.toolChain.release.1051055115/A.NAME/operation=replace -environment/project/io.sloeber.core.toolChain.release.1051055115/A.NAME/value=Arduino Nano +environment/project/io.sloeber.core.toolChain.release.1051055115/A.NAME/value=Arduino Mega or Mega 2560 environment/project/io.sloeber.core.toolChain.release.1051055115/A.PACKAGES/delimiter=; environment/project/io.sloeber.core.toolChain.release.1051055115/A.PACKAGES/operation=replace environment/project/io.sloeber.core.toolChain.release.1051055115/A.PACKAGES/value=${eclipse_home}/arduinoPlugin/packages +environment/project/io.sloeber.core.toolChain.release.1051055115/A.PID.0/delimiter=; +environment/project/io.sloeber.core.toolChain.release.1051055115/A.PID.0/operation=replace +environment/project/io.sloeber.core.toolChain.release.1051055115/A.PID.0/value=0x0010 +environment/project/io.sloeber.core.toolChain.release.1051055115/A.PID.1/delimiter=; +environment/project/io.sloeber.core.toolChain.release.1051055115/A.PID.1/operation=replace +environment/project/io.sloeber.core.toolChain.release.1051055115/A.PID.1/value=0x0042 +environment/project/io.sloeber.core.toolChain.release.1051055115/A.PID.2/delimiter=; +environment/project/io.sloeber.core.toolChain.release.1051055115/A.PID.2/operation=replace +environment/project/io.sloeber.core.toolChain.release.1051055115/A.PID.2/value=0x0010 +environment/project/io.sloeber.core.toolChain.release.1051055115/A.PID.3/delimiter=; +environment/project/io.sloeber.core.toolChain.release.1051055115/A.PID.3/operation=replace +environment/project/io.sloeber.core.toolChain.release.1051055115/A.PID.3/value=0x0042 +environment/project/io.sloeber.core.toolChain.release.1051055115/A.PID.4/delimiter=; +environment/project/io.sloeber.core.toolChain.release.1051055115/A.PID.4/operation=replace +environment/project/io.sloeber.core.toolChain.release.1051055115/A.PID.4/value=0x0210 +environment/project/io.sloeber.core.toolChain.release.1051055115/A.PID.5/delimiter=; +environment/project/io.sloeber.core.toolChain.release.1051055115/A.PID.5/operation=replace +environment/project/io.sloeber.core.toolChain.release.1051055115/A.PID.5/value=0x0242 environment/project/io.sloeber.core.toolChain.release.1051055115/A.PREPROC.INCLUDES.FLAGS/delimiter=; environment/project/io.sloeber.core.toolChain.release.1051055115/A.PREPROC.INCLUDES.FLAGS/operation=replace environment/project/io.sloeber.core.toolChain.release.1051055115/A.PREPROC.INCLUDES.FLAGS/value=-w -x c++ -M -MG -MP @@ -406,16 +424,16 @@ environment/project/io.sloeber.core.toolChain.release.1051055115/A.UPLOAD.ALTID/ environment/project/io.sloeber.core.toolChain.release.1051055115/A.UPLOAD.ALTID/value=no_altID environment/project/io.sloeber.core.toolChain.release.1051055115/A.UPLOAD.MAXIMUM_DATA_SIZE/delimiter=; environment/project/io.sloeber.core.toolChain.release.1051055115/A.UPLOAD.MAXIMUM_DATA_SIZE/operation=replace -environment/project/io.sloeber.core.toolChain.release.1051055115/A.UPLOAD.MAXIMUM_DATA_SIZE/value=2048 +environment/project/io.sloeber.core.toolChain.release.1051055115/A.UPLOAD.MAXIMUM_DATA_SIZE/value=8192 environment/project/io.sloeber.core.toolChain.release.1051055115/A.UPLOAD.MAXIMUM_SIZE/delimiter=; environment/project/io.sloeber.core.toolChain.release.1051055115/A.UPLOAD.MAXIMUM_SIZE/operation=replace -environment/project/io.sloeber.core.toolChain.release.1051055115/A.UPLOAD.MAXIMUM_SIZE/value=30720 +environment/project/io.sloeber.core.toolChain.release.1051055115/A.UPLOAD.MAXIMUM_SIZE/value=253952 environment/project/io.sloeber.core.toolChain.release.1051055115/A.UPLOAD.PROTOCOL/delimiter=; environment/project/io.sloeber.core.toolChain.release.1051055115/A.UPLOAD.PROTOCOL/operation=replace -environment/project/io.sloeber.core.toolChain.release.1051055115/A.UPLOAD.PROTOCOL/value=arduino +environment/project/io.sloeber.core.toolChain.release.1051055115/A.UPLOAD.PROTOCOL/value=wiring environment/project/io.sloeber.core.toolChain.release.1051055115/A.UPLOAD.SPEED/delimiter=; environment/project/io.sloeber.core.toolChain.release.1051055115/A.UPLOAD.SPEED/operation=replace -environment/project/io.sloeber.core.toolChain.release.1051055115/A.UPLOAD.SPEED/value=57600 +environment/project/io.sloeber.core.toolChain.release.1051055115/A.UPLOAD.SPEED/value=115200 environment/project/io.sloeber.core.toolChain.release.1051055115/A.UPLOAD.TOOL/delimiter=; environment/project/io.sloeber.core.toolChain.release.1051055115/A.UPLOAD.TOOL/operation=replace environment/project/io.sloeber.core.toolChain.release.1051055115/A.UPLOAD.TOOL/value=avrdude @@ -425,6 +443,24 @@ environment/project/io.sloeber.core.toolChain.release.1051055115/A.UPLOAD.USBID/ environment/project/io.sloeber.core.toolChain.release.1051055115/A.VERSION/delimiter=; environment/project/io.sloeber.core.toolChain.release.1051055115/A.VERSION/operation=replace environment/project/io.sloeber.core.toolChain.release.1051055115/A.VERSION/value=1.8.2 +environment/project/io.sloeber.core.toolChain.release.1051055115/A.VID.0/delimiter=; +environment/project/io.sloeber.core.toolChain.release.1051055115/A.VID.0/operation=replace +environment/project/io.sloeber.core.toolChain.release.1051055115/A.VID.0/value=0x2341 +environment/project/io.sloeber.core.toolChain.release.1051055115/A.VID.1/delimiter=; +environment/project/io.sloeber.core.toolChain.release.1051055115/A.VID.1/operation=replace +environment/project/io.sloeber.core.toolChain.release.1051055115/A.VID.1/value=0x2341 +environment/project/io.sloeber.core.toolChain.release.1051055115/A.VID.2/delimiter=; +environment/project/io.sloeber.core.toolChain.release.1051055115/A.VID.2/operation=replace +environment/project/io.sloeber.core.toolChain.release.1051055115/A.VID.2/value=0x2A03 +environment/project/io.sloeber.core.toolChain.release.1051055115/A.VID.3/delimiter=; +environment/project/io.sloeber.core.toolChain.release.1051055115/A.VID.3/operation=replace +environment/project/io.sloeber.core.toolChain.release.1051055115/A.VID.3/value=0x2A03 +environment/project/io.sloeber.core.toolChain.release.1051055115/A.VID.4/delimiter=; +environment/project/io.sloeber.core.toolChain.release.1051055115/A.VID.4/operation=replace +environment/project/io.sloeber.core.toolChain.release.1051055115/A.VID.4/value=0x2341 +environment/project/io.sloeber.core.toolChain.release.1051055115/A.VID.5/delimiter=; +environment/project/io.sloeber.core.toolChain.release.1051055115/A.VID.5/operation=replace +environment/project/io.sloeber.core.toolChain.release.1051055115/A.VID.5/value=0x2341 environment/project/io.sloeber.core.toolChain.release.1051055115/JANTJE.ARCHITECTURE_ID/delimiter=; environment/project/io.sloeber.core.toolChain.release.1051055115/JANTJE.ARCHITECTURE_ID/operation=replace environment/project/io.sloeber.core.toolChain.release.1051055115/JANTJE.ARCHITECTURE_ID/value=avr @@ -433,16 +469,16 @@ environment/project/io.sloeber.core.toolChain.release.1051055115/JANTJE.BOARDS_F environment/project/io.sloeber.core.toolChain.release.1051055115/JANTJE.BOARDS_FILE/value=C\:\\Sloeber\\arduinoPlugin\\packages\\arduino\\hardware\\avr\\1.8.2\\boards.txt environment/project/io.sloeber.core.toolChain.release.1051055115/JANTJE.BOARD_ID/delimiter=; environment/project/io.sloeber.core.toolChain.release.1051055115/JANTJE.BOARD_ID/operation=replace -environment/project/io.sloeber.core.toolChain.release.1051055115/JANTJE.BOARD_ID/value=nano +environment/project/io.sloeber.core.toolChain.release.1051055115/JANTJE.BOARD_ID/value=mega environment/project/io.sloeber.core.toolChain.release.1051055115/JANTJE.BOARD_NAME/delimiter=; environment/project/io.sloeber.core.toolChain.release.1051055115/JANTJE.BOARD_NAME/operation=replace -environment/project/io.sloeber.core.toolChain.release.1051055115/JANTJE.BOARD_NAME/value=Arduino Nano +environment/project/io.sloeber.core.toolChain.release.1051055115/JANTJE.BOARD_NAME/value=Arduino Mega or Mega 2560 environment/project/io.sloeber.core.toolChain.release.1051055115/JANTJE.COM_PORT/delimiter=; environment/project/io.sloeber.core.toolChain.release.1051055115/JANTJE.COM_PORT/operation=replace -environment/project/io.sloeber.core.toolChain.release.1051055115/JANTJE.COM_PORT/value=COM6 +environment/project/io.sloeber.core.toolChain.release.1051055115/JANTJE.COM_PORT/value=COM5 environment/project/io.sloeber.core.toolChain.release.1051055115/JANTJE.ECLIPSE_LOCATION/delimiter=; environment/project/io.sloeber.core.toolChain.release.1051055115/JANTJE.ECLIPSE_LOCATION/operation=replace -environment/project/io.sloeber.core.toolChain.release.1051055115/JANTJE.ECLIPSE_LOCATION/value=${eclipse_home} +environment/project/io.sloeber.core.toolChain.release.1051055115/JANTJE.ECLIPSE_LOCATION/value=C\:\\Sloeber\\ environment/project/io.sloeber.core.toolChain.release.1051055115/JANTJE.EXTRA.ALL/delimiter=; environment/project/io.sloeber.core.toolChain.release.1051055115/JANTJE.EXTRA.ALL/operation=replace environment/project/io.sloeber.core.toolChain.release.1051055115/JANTJE.EXTRA.ALL/value= @@ -469,7 +505,7 @@ environment/project/io.sloeber.core.toolChain.release.1051055115/JANTJE.MAKE_LOC environment/project/io.sloeber.core.toolChain.release.1051055115/JANTJE.MAKE_LOCATION/value=C\:\\Sloeber\\arduinoPlugin\\tools\\make\\ environment/project/io.sloeber.core.toolChain.release.1051055115/JANTJE.MENU/delimiter=; environment/project/io.sloeber.core.toolChain.release.1051055115/JANTJE.MENU/operation=replace -environment/project/io.sloeber.core.toolChain.release.1051055115/JANTJE.MENU/value=cpu\=atmega328old +environment/project/io.sloeber.core.toolChain.release.1051055115/JANTJE.MENU/value=cpu\=atmega2560 environment/project/io.sloeber.core.toolChain.release.1051055115/JANTJE.OBJCOPY/delimiter=; environment/project/io.sloeber.core.toolChain.release.1051055115/JANTJE.OBJCOPY/operation=replace environment/project/io.sloeber.core.toolChain.release.1051055115/JANTJE.OBJCOPY/value=${A.RECIPE.OBJCOPY.EEP.PATTERN}\n\t${A.RECIPE.OBJCOPY.HEX.PATTERN} diff --git a/BME280MTTQ.ino b/BME280MTTQ.ino index 3275fa0..deeab2e 100644 --- a/BME280MTTQ.ino +++ b/BME280MTTQ.ino @@ -34,7 +34,6 @@ char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; // Start der UDP-Instanz EthernetUDP Udp; - // DNS DNSClient dnClient; @@ -46,9 +45,7 @@ EthernetServer server(80); void sendUDP(String); void checkUDP(); void clearAll(); -void MQTTreconnect(); -void MQTTcallback(char* , byte* , unsigned int ); - +void MQTTcallback(char*, byte*, unsigned int); //MQTT const char *MQTT_BROKER = "loxberry"; @@ -56,7 +53,6 @@ IPAddress mqttbroker; EthernetClient ethClient; PubSubClient MQTTclient(mqttbroker, 1883, MQTTcallback, ethClient); - void setup() { Wire.begin(); Serial.begin(9600); @@ -70,7 +66,7 @@ void setup() { Serial.println(Ethernet.localIP()); } Udp.begin(localPort); // Start UDP - sendUDP("Raumluft - aktiv"); // send UDP Ready + Serial.println("Raumluft - aktiv"); // send UDP Ready // start the Ethernet connection and the server: server.begin(); @@ -79,15 +75,20 @@ void setup() { if (!bme.begin()) { Serial.println("Could not find a valid BME280 sensor, check wiring!"); - while (1); + while (1) + ; } //DNS Client starten dnClient.begin(Ethernet.dnsServerIP()); - //MQTT Client - MQTTclient.setServer(MQTT_BROKER, 1883); - + if (dnClient.getHostByName(MQTT_BROKER, mqttbroker) == 1) { + Serial.print(F("loxberry = ")); + Serial.println(mqttbroker); + } else { + Serial.print("dns failed"); + mqttbroker.fromString("192.168.1.131"); + } //Serial leeren clearAll(); @@ -101,9 +102,25 @@ void loop() { String temp = String(Temperatur, 2); String hum = String(Humidity, 2); String press = String(Pressure / 100, 2); - + char buff[50]; bme.read(Pressure, Temperatur, Humidity); + //MQTT + if (!MQTTclient.connected()) { + MQTTclient.connect("Stall", "loxberry", "OSVL0AMqISFXgr5g"); + // Abonieren von Nachrichten mit dem angegebenen Topic + MQTTclient.subscribe("/Stall/arduino1/#"); + } + + temp.toCharArray(buff,temp.length()); + MQTTclient.publish("/Stall/Temperatur", buff); + press.toCharArray(buff,press.length()); + MQTTclient.publish("/Stall/Pressure", buff); + hum.toCharArray(buff,hum.length()); + MQTTclient.publish("/Stall/Humidity", buff); + + MQTTclient.loop(); // Schleife für MQTT + // schaut on ein UDP Befehl empfangen wurde checkUDP(); @@ -134,18 +151,11 @@ void loop() { } clearAll(); - // MQTT - if (!MQTTclient.connected()) { - MQTTreconnect(); - } - MQTTclient.loop(); - snprintf(msg, 50, "Alive since %ld milliseconds", millis()); Serial.print("Publish message: "); Serial.println(msg); MQTTclient.publish("/home/data", "Hello World"); - // listen for incoming clients EthernetClient client = server.available(); if (client) { @@ -202,6 +212,7 @@ void loop() { Serial.println("client disonnected"); } + delay(1000); } //// Module //// @@ -235,36 +246,23 @@ void sendUDP(String text) { delay(10); } -void MQTTreconnect() { - while (!MQTTclient.connected()) { - Serial.print("Reconnecting..."); - if (!MQTTclient.connect("BME280")) { - Serial.print("failed, rc="); - Serial.print(MQTTclient.state()); - Serial.println(" retrying in 5 seconds"); - delay(5000); - } +void MQTTcallback(char *topic, byte *payload, unsigned int length) { + Serial.print("Received message ["); + Serial.print(topic); + Serial.print("] "); + char msg[length + 1]; + for (int i = 0; i < length; i++) { + Serial.print((char) payload[i]); + msg[i] = (char) payload[i]; } -} + Serial.println(); -void MQTTcallback(char* topic, byte* payload, unsigned int length) { - Serial.print("Received message ["); - Serial.print(topic); - Serial.print("] "); - char msg[length+1]; - for (int i = 0; i < length; i++) { - Serial.print((char)payload[i]); - msg[i] = (char)payload[i]; - } - Serial.println(); - - msg[length] = '\0'; - Serial.println(msg); - - if(strcmp(msg,"on")==0){ - digitalWrite(13, HIGH); - } - else if(strcmp(msg,"off")==0){ - digitalWrite(13, LOW); - } + msg[length] = '\0'; + Serial.println(msg); + + if (strcmp(msg, "on") == 0) { + digitalWrite(13, HIGH); + } else if (strcmp(msg, "off") == 0) { + digitalWrite(13, LOW); + } } diff --git a/spec.d b/spec.d index 0d55c87..56b9b51 100644 --- a/spec.d +++ b/spec.d @@ -1,2 +1,2 @@ -spec.o: \ - C:/Users/agr/Documents/sloeber-workspace/.metadata/.plugins/org.eclipse.cdt.managedbuilder.core/spec.C +spec.o: \ + C:/Users/Andy.I4A/Documents/sloeber-workspace/.metadata/.plugins/org.eclipse.cdt.managedbuilder.core/spec.C