I try ESP8266 NodeMCU: ESP-NOW Web Server Sensor Dashboard | Random Nerd Tutorials to make it work
With the Arduino IDE it is compiling well
But with PlatformIO I get a lot of Errors
The Code
/*
Rui Santos
Complete project details at https://RandomNerdTutorials.com/esp8266-esp-now-wi-fi-web-server/
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files.
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
*/
#include <espnow.h>
#include <ESP8266WiFi.h>
//#include <Adafruit_BME280.h>
//#include <Adafruit_Sensor.h>
// Set your Board ID (ESP32 Sender #1 = BOARD_ID 1, ESP32 Sender #2 = BOARD_ID 2, etc)
#define BOARD_ID 1
//Adafruit_BME280 bme;
//MAC Address of the receiver
uint8_t broadcastAddress[] = { 0x30,0xAE,0xA4,0x73,0x55,0xF4 };
//Structure example to send data
//Must match the receiver structure
struct tEspMessage {
float Humidity;
float Temperature;
uint32_t Station;
uint32_t Time;
uint32_t Location;
} EspMessage;
//Create a struct_message called myData
tEspMessage myData;
unsigned long previousMillis = 0; // Stores last time temperature was published
const long interval = 10000; // Interval at which to publish sensor readings
// Insert your SSID
constexpr char WIFI_SSID[] = "GigisBoost";
int32_t getWiFiChannel(const char *ssid) {
if (int32_t n = WiFi.scanNetworks()) {
for (uint8_t i=0; i<n; i++) {
if (!strcmp(ssid, WiFi.SSID(i).c_str())) {
return WiFi.channel(i);
}
}
}
return 0;
}
void initBME(){
/*
if (!bme.begin(0x76)) {
Serial.println("Could not find a valid BME280 sensor, check wiring!");
while (1);
}
*/
}
float readTemperature() {
float t = 39.5; //bme.readTemperature();
return t;
}
float readHumidity() {
float h = 95.45; //// bme.readHumidity();
return h;
}
// Callback when data is sent
void OnDataSent(uint8_t *mac_addr, uint8_t sendStatus) {
Serial.print("Last Packet Send Status: ");
if (sendStatus == 0){
Serial.println("Delivery success");
}
else{
Serial.println("Delivery fail");
}
}
void setup() {
//Init Serial Monitor
Serial.begin(115200);
initBME();
// Set device as a Wi-Fi Station and set channel
WiFi.mode(WIFI_STA);
int32_t channel = getWiFiChannel(WIFI_SSID);
WiFi.printDiag(Serial); // Uncomment to verify channel number before
wifi_promiscuous_enable(1);
wifi_set_channel(channel);
wifi_promiscuous_enable(0);
WiFi.printDiag(Serial); // Uncomment to verify channel change after
// Init ESP-NOW
if (esp_now_init() != 0) {
Serial.println("Error initializing ESP-NOW");
return;
}
// Once ESPNow is successfully Init, we will register for Send CB to
// get the status of Trasnmitted packet
esp_now_set_self_role(ESP_NOW_ROLE_CONTROLLER);
esp_now_register_send_cb(OnDataSent);
// esp_now_add_peer(broadcastAddress, ESP_NOW_ROLE_SLAVE, 1, NULL, 0);
}
void loop() {
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
// Save the last time a new reading was published
previousMillis = currentMillis;
//Set values to send
myData.Location = BOARD_ID;
myData.Temperature = readTemperature();
myData.Humidity = readHumidity();
//myData.readingId = readingId++;
esp_now_send(broadcastAddress, (uint8_t *) &myData, sizeof(myData));
Serial.print("loop");
}
}
The Errors
Dependency Graph
|-- Wire @ 1.0
|-- ESP8266WiFi @ 1.0
Building in release mode
Compiling .pio\build\esp12e\src\main.cpp.o
In file included from src\main.cpp:12:
C:\Users\ats37\.platformio\packages\framework-arduinoespressif8266\tools\sdk\include/espnow.h:41:16: error: typedef 'esp_now_recv_cb_t' is initialized (use 'decltype' instead)
41 | typedef void (*esp_now_recv_cb_t)(u8 *mac_addr, u8 *data, u8 len);
| ^~~~~~~~~~~~~~~~~
C:\Users\ats37\.platformio\packages\framework-arduinoespressif8266\tools\sdk\include/espnow.h:41:35: error: 'u8' was not declared in this scope
41 | typedef void (*esp_now_recv_cb_t)(u8 *mac_addr, u8 *data, u8 len);
| ^~
C:\Users\ats37\.platformio\packages\framework-arduinoespressif8266\tools\sdk\include/espnow.h:41:39: error: 'mac_addr' was not declared in this scope
41 | typedef void (*esp_now_recv_cb_t)(u8 *mac_addr, u8 *data, u8 len);
| ^~~~~~~~
C:\Users\ats37\.platformio\packages\framework-arduinoespressif8266\tools\sdk\include/espnow.h:41:49: error: 'u8' was not declared in this scope
41 | typedef void (*esp_now_recv_cb_t)(u8 *mac_addr, u8 *data, u8 len);
| ^~
C:\Users\ats37\.platformio\packages\framework-arduinoespressif8266\tools\sdk\include/espnow.h:41:53: error: 'data' was not declared in this scope
41 | typedef void (*esp_now_recv_cb_t)(u8 *mac_addr, u8 *data, u8 len);
| ^~~~
C:\Users\ats37\.platformio\packages\framework-arduinoespressif8266\tools\sdk\include/espnow.h:41:59: error: 'u8' was not declared in this scope
41 | typedef void (*esp_now_recv_cb_t)(u8 *mac_addr, u8 *data, u8 len);
| ^~
C:\Users\ats37\.platformio\packages\framework-arduinoespressif8266\tools\sdk\include/espnow.h:42:16: error: typedef 'esp_now_send_cb_t' is initialized (use 'decltype' instead)
42 | typedef void (*esp_now_send_cb_t)(u8 *mac_addr, u8 status);
| ^~~~~~~~~~~~~~~~~
C:\Users\ats37\.platformio\packages\framework-arduinoespressif8266\tools\sdk\include/espnow.h:42:35: error: 'u8' was not declared in this scope
42 | typedef void (*esp_now_send_cb_t)(u8 *mac_addr, u8 status);
| ^~
C:\Users\ats37\.platformio\packages\framework-arduinoespressif8266\tools\sdk\include/espnow.h:42:39: error: 'mac_addr' was not declared in this scope
42 | typedef void (*esp_now_send_cb_t)(u8 *mac_addr, u8 status);
| ^~~~~~~~
C:\Users\ats37\.platformio\packages\framework-arduinoespressif8266\tools\sdk\include/espnow.h:42:49: error: 'u8' was not declared in this scope
42 | typedef void (*esp_now_send_cb_t)(u8 *mac_addr, u8 status);
| ^~
C:\Users\ats37\.platformio\packages\framework-arduinoespressif8266\tools\sdk\include/espnow.h:47:30: error: 'esp_now_send_cb_t' was not declared in this scope
47 | int esp_now_register_send_cb(esp_now_send_cb_t cb);
| ^~~~~~~~~~~~~~~~~
C:\Users\ats37\.platformio\packages\framework-arduinoespressif8266\tools\sdk\include/espnow.h:50:30: error: 'esp_now_recv_cb_t' was not declared in this scope
50 | int esp_now_register_recv_cb(esp_now_recv_cb_t cb);
| ^~~~~~~~~~~~~~~~~
C:\Users\ats37\.platformio\packages\framework-arduinoespressif8266\tools\sdk\include/espnow.h:53:18: error: 'u8' was not declared in this scope
53 | int esp_now_send(u8 *da, u8 *data, int len);
| ^~
C:\Users\ats37\.platformio\packages\framework-arduinoespressif8266\tools\sdk\include/espnow.h:53:22: error: 'da' was not declared in this scope
53 | int esp_now_send(u8 *da, u8 *data, int len);
| ^~
C:\Users\ats37\.platformio\packages\framework-arduinoespressif8266\tools\sdk\include/espnow.h:53:26: error: 'u8' was not declared in this scope
53 | int esp_now_send(u8 *da, u8 *data, int len);
| ^~
C:\Users\ats37\.platformio\packages\framework-arduinoespressif8266\tools\sdk\include/espnow.h:53:30: error: 'data' was not declared in this scope
53 | int esp_now_send(u8 *da, u8 *data, int len);
| ^~~~
C:\Users\ats37\.platformio\packages\framework-arduinoespressif8266\tools\sdk\include/espnow.h:53:36: error: expected primary-expression before 'int'
53 | int esp_now_send(u8 *da, u8 *data, int len);
| ^~~
C:\Users\ats37\.platformio\packages\framework-arduinoespressif8266\tools\sdk\include/espnow.h:53:43: error: expression list treated as compound expression in initializer [-fpermissive]
53 | int esp_now_send(u8 *da, u8 *data, int len);
| ^
C:\Users\ats37\.platformio\packages\framework-arduinoespressif8266\tools\sdk\include/espnow.h:55:22: error: 'u8' was not declared in this scope
55 | int esp_now_add_peer(u8 *mac_addr, u8 role, u8 channel, u8 *key, u8 key_len);
| ^~
C:\Users\ats37\.platformio\packages\framework-arduinoespressif8266\tools\sdk\include/espnow.h:55:26: error: 'mac_addr' was not declared in this scope
55 | int esp_now_add_peer(u8 *mac_addr, u8 role, u8 channel, u8 *key, u8 key_len);
| ^~~~~~~~
C:\Users\ats37\.platformio\packages\framework-arduinoespressif8266\tools\sdk\include/espnow.h:55:36: error: 'u8' was not declared in this scope
55 | int esp_now_add_peer(u8 *mac_addr, u8 role, u8 channel, u8 *key, u8 key_len);
| ^~
C:\Users\ats37\.platformio\packages\framework-arduinoespressif8266\tools\sdk\include/espnow.h:55:45: error: 'u8' was not declared in this scope
55 | int esp_now_add_peer(u8 *mac_addr, u8 role, u8 channel, u8 *key, u8 key_len);
| ^~
C:\Users\ats37\.platformio\packages\framework-arduinoespressif8266\tools\sdk\include/espnow.h:55:57: error: 'u8' was not declared in this scope
55 | int esp_now_add_peer(u8 *mac_addr, u8 role, u8 channel, u8 *key, u8 key_len);
| ^~
C:\Users\ats37\.platformio\packages\framework-arduinoespressif8266\tools\sdk\include/espnow.h:55:61: error: 'key' was not declared in this scope
55 | int esp_now_add_peer(u8 *mac_addr, u8 role, u8 channel, u8 *key, u8 key_len);
| ^~~
C:\Users\ats37\.platformio\packages\framework-arduinoespressif8266\tools\sdk\include/espnow.h:55:66: error: 'u8' was not declared in this scope
55 | int esp_now_add_peer(u8 *mac_addr, u8 role, u8 channel, u8 *key, u8 key_len);
| ^~
C:\Users\ats37\.platformio\packages\framework-arduinoespressif8266\tools\sdk\include/espnow.h:55:76: error: expression list treated as compound expression in initializer [-fpermissive]
55 | int esp_now_add_peer(u8 *mac_addr, u8 role, u8 channel, u8 *key, u8 key_len);
| ^
C:\Users\ats37\.platformio\packages\framework-arduinoespressif8266\tools\sdk\include/espnow.h:56:22: error: 'u8' was not declared in this scope
56 | int esp_now_del_peer(u8 *mac_addr);
| ^~
C:\Users\ats37\.platformio\packages\framework-arduinoespressif8266\tools\sdk\include/espnow.h:56:26: error: 'mac_addr' was not declared in this scope
56 | int esp_now_del_peer(u8 *mac_addr);
| ^~~~~~~~
C:\Users\ats37\.platformio\packages\framework-arduinoespressif8266\tools\sdk\include/espnow.h:58:27: error: 'u8' was not declared in this scope
58 | int esp_now_set_self_role(u8 role);
| ^~
C:\Users\ats37\.platformio\packages\framework-arduinoespressif8266\tools\sdk\include/espnow.h:61:27: error: 'u8' was not declared in this scope
61 | int esp_now_set_peer_role(u8 *mac_addr, u8 role);
| ^~
C:\Users\ats37\.platformio\packages\framework-arduinoespressif8266\tools\sdk\include/espnow.h:61:31: error: 'mac_addr' was not declared in this scope
61 | int esp_now_set_peer_role(u8 *mac_addr, u8 role);
| ^~~~~~~~
C:\Users\ats37\.platformio\packages\framework-arduinoespressif8266\tools\sdk\include/espnow.h:61:41: error: 'u8' was not declared in this scope
61 | int esp_now_set_peer_role(u8 *mac_addr, u8 role);
| ^~
C:\Users\ats37\.platformio\packages\framework-arduinoespressif8266\tools\sdk\include/espnow.h:61:48: error: expression list treated as compound expression in initializer [-fpermissive]
61 | int esp_now_set_peer_role(u8 *mac_addr, u8 role);
| ^
C:\Users\ats37\.platformio\packages\framework-arduinoespressif8266\tools\sdk\include/espnow.h:62:27: error: 'u8' was not declared in this scope
62 | int esp_now_get_peer_role(u8 *mac_addr);
| ^~
C:\Users\ats37\.platformio\packages\framework-arduinoespressif8266\tools\sdk\include/espnow.h:62:31: error: 'mac_addr' was not declared in this scope
62 | int esp_now_get_peer_role(u8 *mac_addr);
| ^~~~~~~~
C:\Users\ats37\.platformio\packages\framework-arduinoespressif8266\tools\sdk\include/espnow.h:64:30: error: 'u8' was not declared in this scope
64 | int esp_now_set_peer_channel(u8 *mac_addr, u8 channel);
| ^~
C:\Users\ats37\.platformio\packages\framework-arduinoespressif8266\tools\sdk\include/espnow.h:64:34: error: 'mac_addr' was not declared in this scope
64 | int esp_now_set_peer_channel(u8 *mac_addr, u8 channel);
| ^~~~~~~~
C:\Users\ats37\.platformio\packages\framework-arduinoespressif8266\tools\sdk\include/espnow.h:64:44: error: 'u8' was not declared in this scope
64 | int esp_now_set_peer_channel(u8 *mac_addr, u8 channel);
| ^~
C:\Users\ats37\.platformio\packages\framework-arduinoespressif8266\tools\sdk\include/espnow.h:64:54: error: expression list treated as compound expression in initializer [-fpermissive]
64 | int esp_now_set_peer_channel(u8 *mac_addr, u8 channel);
| ^
C:\Users\ats37\.platformio\packages\framework-arduinoespressif8266\tools\sdk\include/espnow.h:65:30: error: 'u8' was not declared in this scope
65 | int esp_now_get_peer_channel(u8 *mac_addr);
| ^~
C:\Users\ats37\.platformio\packages\framework-arduinoespressif8266\tools\sdk\include/espnow.h:65:34: error: 'mac_addr' was not declared in this scope
65 | int esp_now_get_peer_channel(u8 *mac_addr);
| ^~~~~~~~
C:\Users\ats37\.platformio\packages\framework-arduinoespressif8266\tools\sdk\include/espnow.h:67:26: error: 'u8' was not declared in this scope
67 | int esp_now_set_peer_key(u8 *mac_addr, u8 *key, u8 key_len);
| ^~
C:\Users\ats37\.platformio\packages\framework-arduinoespressif8266\tools\sdk\include/espnow.h:67:30: error: 'mac_addr' was not declared in this scope
67 | int esp_now_set_peer_key(u8 *mac_addr, u8 *key, u8 key_len);
| ^~~~~~~~
C:\Users\ats37\.platformio\packages\framework-arduinoespressif8266\tools\sdk\include/espnow.h:67:40: error: 'u8' was not declared in this scope
67 | int esp_now_set_peer_key(u8 *mac_addr, u8 *key, u8 key_len);
| ^~
C:\Users\ats37\.platformio\packages\framework-arduinoespressif8266\tools\sdk\include/espnow.h:67:44: error: 'key' was not declared in this scope
67 | int esp_now_set_peer_key(u8 *mac_addr, u8 *key, u8 key_len);
| ^~~
C:\Users\ats37\.platformio\packages\framework-arduinoespressif8266\tools\sdk\include/espnow.h:67:49: error: 'u8' was not declared in this scope
67 | int esp_now_set_peer_key(u8 *mac_addr, u8 *key, u8 key_len);
| ^~
C:\Users\ats37\.platformio\packages\framework-arduinoespressif8266\tools\sdk\include/espnow.h:67:59: error: expression list treated as compound expression in initializer [-fpermissive]
67 | int esp_now_set_peer_key(u8 *mac_addr, u8 *key, u8 key_len);
| ^
C:\Users\ats37\.platformio\packages\framework-arduinoespressif8266\tools\sdk\include/espnow.h:68:26: error: 'u8' was not declared in this scope
68 | int esp_now_get_peer_key(u8 *mac_addr, u8 *key, u8 *key_len);
| ^~
C:\Users\ats37\.platformio\packages\framework-arduinoespressif8266\tools\sdk\include/espnow.h:68:30: error: 'mac_addr' was not declared in this scope
68 | int esp_now_get_peer_key(u8 *mac_addr, u8 *key, u8 *key_len);
| ^~~~~~~~
C:\Users\ats37\.platformio\packages\framework-arduinoespressif8266\tools\sdk\include/espnow.h:68:40: error: 'u8' was not declared in this scope
68 | int esp_now_get_peer_key(u8 *mac_addr, u8 *key, u8 *key_len);
| ^~
C:\Users\ats37\.platformio\packages\framework-arduinoespressif8266\tools\sdk\include/espnow.h:68:44: error: 'key' was not declared in this scope
68 | int esp_now_get_peer_key(u8 *mac_addr, u8 *key, u8 *key_len);
| ^~~
C:\Users\ats37\.platformio\packages\framework-arduinoespressif8266\tools\sdk\include/espnow.h:68:49: error: 'u8' was not declared in this scope
68 | int esp_now_get_peer_key(u8 *mac_addr, u8 *key, u8 *key_len);
| ^~
C:\Users\ats37\.platformio\packages\framework-arduinoespressif8266\tools\sdk\include/espnow.h:68:53: error: 'key_len' was not declared in this scope
68 | int esp_now_get_peer_key(u8 *mac_addr, u8 *key, u8 *key_len);
| ^~~~~~~
C:\Users\ats37\.platformio\packages\framework-arduinoespressif8266\tools\sdk\include/espnow.h:68:60: error: expression list treated as compound expression in initializer [-fpermissive]
68 | int esp_now_get_peer_key(u8 *mac_addr, u8 *key, u8 *key_len);
| ^
C:\Users\ats37\.platformio\packages\framework-arduinoespressif8266\tools\sdk\include/espnow.h:70:1: error: 'u8' does not name a type
70 | u8 *esp_now_fetch_peer(bool restart);
| ^~
C:\Users\ats37\.platformio\packages\framework-arduinoespressif8266\tools\sdk\include/espnow.h:72:27: error: 'u8' was not declared in this scope
72 | int esp_now_is_peer_exist(u8 *mac_addr);
| ^~
C:\Users\ats37\.platformio\packages\framework-arduinoespressif8266\tools\sdk\include/espnow.h:72:31: error: 'mac_addr' was not declared in this scope
72 | int esp_now_is_peer_exist(u8 *mac_addr);
| ^~~~~~~~
C:\Users\ats37\.platformio\packages\framework-arduinoespressif8266\tools\sdk\include/espnow.h:74:26: error: 'u8' was not declared in this scope
74 | int esp_now_get_cnt_info(u8 *all_cnt, u8 *encrypt_cnt);
| ^~
C:\Users\ats37\.platformio\packages\framework-arduinoespressif8266\tools\sdk\include/espnow.h:74:30: error: 'all_cnt' was not declared in this scope
74 | int esp_now_get_cnt_info(u8 *all_cnt, u8 *encrypt_cnt);
| ^~~~~~~
C:\Users\ats37\.platformio\packages\framework-arduinoespressif8266\tools\sdk\include/espnow.h:74:39: error: 'u8' was not declared in this scope
74 | int esp_now_get_cnt_info(u8 *all_cnt, u8 *encrypt_cnt);
| ^~
C:\Users\ats37\.platformio\packages\framework-arduinoespressif8266\tools\sdk\include/espnow.h:74:43: error: 'encrypt_cnt' was not declared in this scope
74 | int esp_now_get_cnt_info(u8 *all_cnt, u8 *encrypt_cnt);
| ^~~~~~~~~~~
C:\Users\ats37\.platformio\packages\framework-arduinoespressif8266\tools\sdk\include/espnow.h:74:54: error: expression list treated as compound expression in initializer [-fpermissive]
74 | int esp_now_get_cnt_info(u8 *all_cnt, u8 *encrypt_cnt);
| ^
C:\Users\ats37\.platformio\packages\framework-arduinoespressif8266\tools\sdk\include/espnow.h:76:21: error: 'u8' was not declared in this scope
76 | int esp_now_set_kok(u8 *key, u8 len);
| ^~
C:\Users\ats37\.platformio\packages\framework-arduinoespressif8266\tools\sdk\include/espnow.h:76:25: error: 'key' was not declared in this scope
76 | int esp_now_set_kok(u8 *key, u8 len);
| ^~~
C:\Users\ats37\.platformio\packages\framework-arduinoespressif8266\tools\sdk\include/espnow.h:76:30: error: 'u8' was not declared in this scope
76 | int esp_now_set_kok(u8 *key, u8 len);
| ^~
C:\Users\ats37\.platformio\packages\framework-arduinoespressif8266\tools\sdk\include/espnow.h:76:36: error: expression list treated as compound expression in initializer [-fpermissive]
76 | int esp_now_set_kok(u8 *key, u8 len);
| ^
src\main.cpp: In function 'void setup()':
src\main.cpp:109:49: error: 'esp_now_set_self_role' cannot be used as a function
109 | esp_now_set_self_role(ESP_NOW_ROLE_CONTROLLER);
| ^
src\main.cpp:111:38: error: 'esp_now_register_send_cb' cannot be used as a function
111 | esp_now_register_send_cb(OnDataSent);
| ^
src\main.cpp: In function 'void loop()':
src\main.cpp:127:71: error: 'esp_now_send' cannot be used as a function
127 | esp_now_send(broadcastAddress, (uint8_t *) &myData, sizeof(myData));
| ^
*** [.pio\build\esp12e\src\main.cpp.o] Error 1
================================================================================================================================ [FAILED] Took 2.07 seconds ================================================================================================================================
* The terminal process "C:\Users\ats37\.platformio\penv\Scripts\platformio.exe 'run', '--environment', 'esp12e'" terminated with exit code: 1.
* Terminal will be reused by tasks, press any key to close it.