I am getting error messages in VSCode I cannot deduct from the code (a simple UDP server test). The code is compiling and running fine. Errors are as follows:
My platformio.ini
is:
[env:az-delivery-devkit-v4]
platform = espressif32
board = az-delivery-devkit-v4
framework = arduino
lib_deps =
Ethernet=https://github.com/arduino-libraries/Ethernet.git
monitor_speed = 115200
monitor_dtr = 0
monitor_rts = 0
lib_ldf_mode = deep+
monitor_filters = esp32_exception_decoder
build_flags = -DMY_SSID=\"hidden\" -DMY_PASS=\"hidden_as_well\"
The code is:
#include <Arduino.h>
#define UDPMODE 2
#if UDPMODE == 1
#include <WiFi.h>
#include <WiFiUdp.h>
#elif UDPMODE == 2
#include <Ethernet.h>
#include <EthernetUdp.h>
#endif
/* WiFi network name and password */
const char * ssid = MY_SSID;
const char * pwd = MY_PASS;
// IP address to send UDP data to.
// it can be ip address of the server or
// a network broadcast address
// here is broadcast address
// const char * udpAddress = "192.168.1.100";
const int udpPort = 502;
//create UDP instance
#if UDPMODE == 1
WiFiUDP udp;
#elif UDPMODE == 2
// The WIZ5500 module needs the reset line connected to a GPIO
#define RESET_P GPIO_NUM_26
EthernetUDP udp;
// Reset W5500 module
void WizReset() {
Serial.print("Resetting Wiz W5500 Ethernet Board... ");
pinMode(RESET_P, OUTPUT);
digitalWrite(RESET_P, HIGH);
delay(250);
digitalWrite(RESET_P, LOW);
delay(50);
digitalWrite(RESET_P, HIGH);
delay(350);
Serial.print("Done.\n");
}
#endif
void setup(){
Serial.begin(115200);
Serial.println("");
#if UDPMODE == 1
//Connect to the WiFi network
WiFi.begin(ssid, pwd);
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
#elif UDPMODE == 2
// Fire up Ethernet
Ethernet.init(5);
IPAddress lIP;
byte mac[6]={0xAA,0xAB,0xAC,0xAD,0xAE,0xAF}; // Fill in appropriate values here!
// prime the WIZ5500 module
WizReset();
// Try to get an IP via DHCP
if (Ethernet.begin(mac) == 0) {
// No. DHCP did not work.
Serial.print("Failed to configure Ethernet using DHCP\n");
// Check for Ethernet hardware present
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
Serial.print("Ethernet shield was not found. Sorry, can't run without hardware. :(\n");
} else {
if (Ethernet.linkStatus() == LinkOFF) {
Serial.print("Ethernet cable is not connected.\n");
}
}
while (1) {} // Do nothing any more
}
// We seem to have a connection to the router
lIP = Ethernet.localIP();
Serial.printf("My IP address: %u.%u.%u.%u\n", lIP[0], lIP[1], lIP[2], lIP[3]);
#endif
//This initializes udp and transfer buffer
udp.begin(udpPort);
}
void loop(){
//processing incoming packet, must be called before reading the buffer
uint32_t bts = udp.parsePacket();
//receive response from server, it will be HELLO WORLD
if (bts) {
char *buffer = new char[bts + 1];
if(udp.read(buffer, bts) > 0){
buffer[bts] = 0;
Serial.print(buffer);
}
delete[] buffer;
}
}
I suppose the static code check is missing to scan platformio.ini
for additional defines and include paths, but why?