- Notifications
You must be signed in to change notification settings - Fork13.3k
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
Hello everybody I am trying to compile this code with Arduino ide on a esp8266 but I get this error on line 45: Thanks everyone #include<ESP8266WiFi.h>#include<PubSubClient.h>#include<Arduino.h>#defineWIFI_SSID"wifissid"#defineWIFI_PASSWORD"password"#defineMQTT_SERVER"10.25.73.8"#defineMQTT_PORT1883// use 8883 for SSL#defineMQTT_USER"pi"//user for Mosquitto#defineMQTT_PASSWORD"raspberry"//passord for Mosquitto#definerain_topic"sensor/rain"//Topic Rainconstint sensorMin =0;// sensor minimumconstint sensorMax =1024;// sensor maximumchar message_buff[100];bool debug =true;WiFiClient espClient;PubSubClientclient(espClient);voidsetup() {Serial.begin(9600);pinMode(A0, INPUT);setup_wifi();client.setServer(MQTT_SERVER, MQTT_PORT);client.setCallback(callback);//Connecfion WiFivoidsetup_wifi() {delay(10);// We start by connecting to a WiFi networkSerial.println();Serial.print("Connecting to");Serial.println(WIFI_SSID);WiFi.mode(WIFI_STA);WiFi.begin(WIFI_SSID, WIFI_PASSWORD);while (WiFi.status() != WL_CONNECTED) {delay(500);Serial.print(".");}Serial.println("");Serial.println("WiFi connected");Serial.print("=> IP address:");Serial.print(WiFi.localIP());Serial.println("");}//Reconnexionvoidreconnect() {while (!client.connected()) {Serial.print("Attempting MQTT connection...");// Attempt to connectif (client.connect("ESP8266Client", MQTT_USER, MQTT_PASSWORD)) {Serial.println("Connected");}else {Serial.print("Failed, Error:");Serial.print(client.state());Serial.println(" Retrying MQTT connection in 5 seconds...");delay(5000);// Wait 5 seconds before retrying}}}voidloop() {if (!client.connected()){reconnect();}client.loop();int sensorReading =analogRead(A0);int range =map(sensorReading, sensorMin, sensorMax,0,3);// range value:switch (range) {case0:// Sensor getting wetSerial.println("Flood");client.publish(rain_topic,"Flood",true);break;case1:// Sensor getting wetSerial.println("Rain Warning");client.publish(rain_topic,"raining",true);break;case2:// Sensor dry - To shut this up delete the " Serial.println("Not Raining"); " below.Serial.println("Sun");client.publish(rain_topic,"sun",true);break;}delay(1000 *10);// delay between reads}// Start after receiving the messagevoidcallback(char* topic, byte* payload,unsignedint length) {int i =0;if ( debug ) {Serial.println("Message recu => topic:" +String(topic));Serial.print(" | longueur:" +String(length, DEC));}// create character buffer with ending null terminator (string)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);}} |
BetaWas this translation helpful?Give feedback.
All reactions
Replies: 1 comment
-
This is an Arduino code where it is not mandatory to declare function before their use. This is made possible with an Arduino specific preprocessing on source code aimed at beginners and often counter-productive. What you can do is adding this single line Similar issue:https://community.platformio.org/t/code-works-in-arduino-ide-but-not-platformio/1907 |
BetaWas this translation helpful?Give feedback.