#include <WiFi.h>
#include <PubSubClient.h>
#include <Wire.h>
#include<ArduinoJson.h>
#include <SPI.h>
#include <LoRa.h>
#include <NTPClient.h>
#include <WiFiUdp.h>
bool a;
char hfhnfgh[1024];
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP);
const char* ssid = "Zeptogreens";
const char* password = "Zeptogreens@2023";
// Add your MQTT Broker IP address, example:
//const char* mqtt_server = "192.168.1.144";
const char* mqtt_server = "192.168.0.186";
const char* mqttUsername = "Zeptogreens";
const char* mqttpsw = "123456";
const char* TOPIC = "KIKIK";
WiFiClient espClient;
PubSubClient client(espClient);
void setup_wifi() {
delay(10);
// We start by connecting to a WiFi network
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
void callback(char* topic, byte* payload, unsigned int length) {
Serial.print("Message arrived on topic: ");
Serial.print(topic);
Serial.print(". Message: ");
Serial.println();
}
void reconnect() {
// Loop until we're reconnected
while (!client.connected()) {
Serial.print("Attempting MQTT connection...");
// Attempt to connect
if (client.connect("ESP8266Client", mqttUsername, mqttpsw)) {
Serial.println("connected");
// Subscribe
// client.subscribe(ZoneNSensor);
a = true;
} else {
a = false;
Serial.print("failed, rc=");
Serial.print(client.state());
Serial.println(" try again in 5 seconds");
// Wait 5 seconds before retrying
delay(5000);
}
}
}
void sensor()
{
DynamicJsonDocument doc(500);
JsonObject mydoc = doc.createNestedObject("info");
mydoc["rollnum"]=1233;
mydoc["name "]="sensor";
mydoc["school"]="didnt go";
serializeJson(doc,Serial);
serializeJson(doc,hfhnfgh);
client.publish(TOPIC,hfhnfgh);
}
void setup() {
Serial.begin(115200);
setup_wifi();
client.setServer(mqtt_server, 1883);
client.setCallback(callback);
}
void loop() {
if (!client.connected()) {
reconnect();
}
client.loop();
delay(3000);
sensor();
}
Arduino: 1.8.19 (Windows 10), Board: "Generic ESP8266 Module, 80 MHz, Flash, Disabled (new aborts on oom), Disabled, All SSL ciphers (most compatible), 32KB cache + 32KB IRAM (balanced), Use pgm_read macros for IRAM/PROGMEM, dtr (aka nodemcu), 26 MHz, 40MHz, DOUT (compatible), 1MB (FS:64KB OTA:~470KB), 2, nonos-sdk 2.2.1+100 (190703), v2 Lower Memory, Disabled, None, Only Sketch, 115200"
In file included from c:\users\dell\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\3.0.4-gcc10.3-1757bed\xtensa-lx106-elf\include\assert.h:10,
from c:\users\dell\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\3.0.4-gcc10.3-1757bed\xtensa-lx106-elf\include\sys\reent.h:503,
from c:\users\dell\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\3.0.4-gcc10.3-1757bed\xtensa-lx106-elf\include\stdlib.h:18,
from c:\users\dell\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\3.0.4-gcc10.3-1757bed\xtensa-lx106-elf\include\c++\10.3.0\cstdlib:75,
from c:\users\dell\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\3.0.4-gcc10.3-1757bed\xtensa-lx106-elf\include\c++\10.3.0\stdlib.h:36,
from C:\Users\DELL\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.2\cores\esp8266/Arduino.h:27,
from C:\Users\DELL\Documents\Arduino\libraries\WiFiEspAT\src\utility\EspAtDrv.h:23,
from C:\Users\DELL\Documents\Arduino\libraries\WiFiEspAT\src\utility\EspAtDrv.cpp:20:
C:\Users\DELL\Documents\Arduino\libraries\WiFiEspAT\src\utility\EspAtDrv.cpp:37:17: error: 'const char OK []' redeclared as different kind of entity
37 | const char OK[] PROGMEM = "OK";
| ^~~~~~~
In file included from C:\Users\DELL\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.2\cores\esp8266/esp8266_peri.h:27,
from C:\Users\DELL\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.2\cores\esp8266/Arduino.h:38,
from C:\Users\DELL\Documents\Arduino\libraries\WiFiEspAT\src\utility\EspAtDrv.h:23,
from C:\Users\DELL\Documents\Arduino\libraries\WiFiEspAT\src\utility\EspAtDrv.cpp:20:
C:\Users\DELL\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.2/tools/sdk/include/c_types.h:71:5: note: previous declaration 'STATUS OK'
71 | OK = 0,
| ^~
In file included from c:\users\dell\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\3.0.4-gcc10.3-1757bed\xtensa-lx106-elf\include\assert.h:10,
from c:\users\dell\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\3.0.4-gcc10.3-1757bed\xtensa-lx106-elf\include\sys\reent.h:503,
from c:\users\dell\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\3.0.4-gcc10.3-1757bed\xtensa-lx106-elf\include\stdlib.h:18,
from c:\users\dell\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\3.0.4-gcc10.3-1757bed\xtensa-lx106-elf\include\c++\10.3.0\cstdlib:75,
from c:\users\dell\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\3.0.4-gcc10.3-1757bed\xtensa-lx106-elf\include\c++\10.3.0\stdlib.h:36,
from C:\Users\DELL\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.2\cores\esp8266/Arduino.h:27,
from C:\Users\DELL\Documents\Arduino\libraries\WiFiEspAT\src\utility\EspAtDrv.h:23,
from C:\Users\DELL\Documents\Arduino\libraries\WiFiEspAT\src\utility\EspAtDrv.cpp:20:
C:\Users\DELL\Documents\Arduino\libraries\WiFiEspAT\src\utility\EspAtDrv.cpp:38:21: error: 'const char STATUS []' redeclared as different kind of entity
38 | const char STATUS[] PROGMEM = "STATUS";
| ^~~~~~~
In file included from C:\Users\DELL\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.2\cores\esp8266/esp8266_peri.h:27,
from C:\Users\DELL\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.2\cores\esp8266/Arduino.h:38,
from C:\Users\DELL\Documents\Arduino\libraries\WiFiEspAT\src\utility\EspAtDrv.h:23,
from C:\Users\DELL\Documents\Arduino\libraries\WiFiEspAT\src\utility\EspAtDrv.cpp:20:
C:\Users\DELL\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.2/tools/sdk/include/c_types.h:76:3: note: previous declaration 'typedef enum STATUS STATUS'
76 | } STATUS;
| ^~~~~~
C:\Users\DELL\Documents\Arduino\libraries\WiFiEspAT\src\utility\EspAtDrv.cpp: In member function 'int EspAtDrvClass::staStatus()':
C:\Users\DELL\Documents\Arduino\libraries\WiFiEspAT\src\utility\EspAtDrv.cpp:180:26: error: expected primary-expression before ')' token
180 | if (!sendCommand(STATUS))
| ^
C:\Users\DELL\Documents\Arduino\libraries\WiFiEspAT\src\utility\EspAtDrv.cpp: In member function 'bool EspAtDrvClass::remoteParamsQuery(uint8_t, IPAddress&, uint16_t&)':
C:\Users\DELL\Documents\Arduino\libraries\WiFiEspAT\src\utility\EspAtDrv.cpp:855:28: error: expected primary-expression before ')' token
855 | if (!sendCommand(STATUS))
| ^
In file included from c:\users\dell\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\3.0.4-gcc10.3-1757bed\xtensa-lx106-elf\include\string.h:175,
from C:\Users\DELL\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.2\cores\esp8266/Arduino.h:33,
from C:\Users\DELL\Documents\Arduino\libraries\WiFiEspAT\src\utility\EspAtDrv.h:23,
from C:\Users\DELL\Documents\Arduino\libraries\WiFiEspAT\src\utility\EspAtDrv.cpp:20:
C:\Users\DELL\Documents\Arduino\libraries\WiFiEspAT\src\utility\EspAtDrv.cpp: In member function 'size_t EspAtDrvClass::sendData(uint8_t, const uint8_t*, size_t, const char*, uint16_t)':
C:\Users\DELL\Documents\Arduino\libraries\WiFiEspAT\src\utility\EspAtDrv.cpp:1090:42: error: cannot convert 'STATUS' to 'const char*'
1090 | if (strcmp_P(buffer + strlen("SEND "), OK) != 0) {// FAIL
| ^
| |
| STATUS
c:\users\dell\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\3.0.4-gcc10.3-1757bed\xtensa-lx106-elf\include\sys\string.h:38:30: note: initializing argument 2 of 'int strncmp_P(const char*, const char*, size_t)'
38 | int strncmp_P(const char *, const char *, size_t);
| ^~~~~~~~~~~~
C:\Users\DELL\Documents\Arduino\libraries\WiFiEspAT\src\utility\EspAtDrv.cpp: In member function 'size_t EspAtDrvClass::sendData(uint8_t, Stream&, const char*, uint16_t)':
C:\Users\DELL\Documents\Arduino\libraries\WiFiEspAT\src\utility\EspAtDrv.cpp:1147:70: error: cannot convert 'STATUS' to 'const char*'
1147 | if (!readRX(PSTR("SEND ")) || strcmp_P(buffer + strlen("SEND "), OK) != 0) {// FAIL
| ^
| |
| STATUS
c:\users\dell\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\3.0.4-gcc10.3-1757bed\xtensa-lx106-elf\include\sys\string.h:38:30: note: initializing argument 2 of 'int strncmp_P(const char*, const char*, size_t)'
38 | int strncmp_P(const char *, const char *, size_t);
| ^~~~~~~~~~~~
C:\Users\DELL\Documents\Arduino\libraries\WiFiEspAT\src\utility\EspAtDrv.cpp: In member function 'size_t EspAtDrvClass::sendData(uint8_t, SendCallbackFnc, const char*, uint16_t)':
C:\Users\DELL\Documents\Arduino\libraries\WiFiEspAT\src\utility\EspAtDrv.cpp:1204:42: error: cannot convert 'STATUS' to 'const char*'
1204 | if (strcmp_P(buffer + strlen("SEND "), OK) != 0) {// FAIL
| ^
| |
| STATUS
c:\users\dell\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\3.0.4-gcc10.3-1757bed\xtensa-lx106-elf\include\sys\string.h:38:30: note: initializing argument 2 of 'int strncmp_P(const char*, const char*, size_t)'
38 | int strncmp_P(const char *, const char *, size_t);
| ^~~~~~~~~~~~
C:\Users\DELL\Documents\Arduino\libraries\WiFiEspAT\src\utility\EspAtDrv.cpp: In member function 'bool EspAtDrvClass::readRX(const char*, bool, bool)':
C:\Users\DELL\Documents\Arduino\libraries\WiFiEspAT\src\utility\EspAtDrv.cpp:1543:46: error: cannot convert 'STATUS' to 'const char*'
1543 | } else if (listItem && !strcmp_P(buffer, OK)) { // OK ends the listing of unknown items count
| ^
| |
| STATUS
c:\users\dell\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\3.0.4-gcc10.3-1757bed\xtensa-lx106-elf\include\sys\string.h:38:30: note: initializing argument 2 of 'int strncmp_P(const char*, const char*, size_t)'
38 | int strncmp_P(const char *, const char *, size_t);
| ^~~~~~~~~~~~
C:\Users\DELL\Documents\Arduino\libraries\WiFiEspAT\src\utility\EspAtDrv.cpp: In member function 'bool EspAtDrvClass::readOK()':
C:\Users\DELL\Documents\Arduino\libraries\WiFiEspAT\src\utility\EspAtDrv.cpp:1560:17: error: cannot convert 'STATUS' to 'const char*'
1560 | return readRX(OK);
| ^~
| |
| STATUS
C:\Users\DELL\Documents\Arduino\libraries\WiFiEspAT\src\utility\EspAtDrv.cpp:1393:34: note: initializing argument 1 of 'bool EspAtDrvClass::readRX(const char*, bool, bool)'
1393 | bool EspAtDrvClass::readRX(PGM_P expected, bool bufferData, bool listItem) {
| ^
C:\Users\DELL\Documents\Arduino\libraries\WiFiEspAT\src\utility\EspAtDrv.cpp: In member function 'bool EspAtDrvClass::checkLinks()':
C:\Users\DELL\Documents\Arduino\libraries\WiFiEspAT\src\utility\EspAtDrv.cpp:1677:26: error: expected primary-expression before ')' token
1677 | if (!sendCommand(STATUS))
| ^
exit status 1
Error compiling for board Generic ESP8266 Module.
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
I have created JsonPackage and sending data to MQTT server but esp8266 board is not supporting can any one check this error.
the ESP8266 WiFi library is ESP8266WiFi.h not WiFi.h
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.