Bonjour,
J'aimerai envoyer des données via le WIFI de mon ordinateur depuis le serial monitor et les recevoir sur l'ESP 32.
Mais je rencontre cette erreur
Compilation error: 'class WiFiUDP' has no member named 'localPort'
Merci pour votre aide
Pour lancer le programme il faut commenter la ligne 73
Ce programme à l'avenir devra me permettre d'envoyer et recevoir des messages osc depuis l'ESP32
// ESP32 UDP client sending datagrams to a UDP server
// from https://github.com/evothings/evothings-examples/blob/master/examples/arduino-led-onoff-tcp/arduinowifi/arduinowifi/arduinowifi.ino
#include <WiFi.h>
#include <WiFiUdp.h>
#include <OSCMessage.h>
WiFiUDP Udp;
const unsigned int outPort = 8000; // remote port to receive OSC
const unsigned int localPort = 8001; // local port to listen for OSC packets (actually not used for sending)
// network SSID (network name). and network password.
//char ssid[] = "****";
//char pass[] = "****";
//char ssid[] = "SFR-d078"; // your network SSID (name)
//char pass[] = "DEDW3VPARYGZ"; // your network password
char ssid[] = "Iphone de ben"; // your network SSID (name)
char pass[] = "cacaprout"; // your network password
// network key Index number (needed only for WEP).
int keyIndex = 0;
// UDP information
//local broadcast address..
IPAddress udpServer(192, 168, 0, 255);
IPAddress outIp(127, 0, 0, 1); //127.0.0.1
#define UDP_PORT 8002
WiFiUDP udp;
// UDP Datagram
struct __attribute__((packed)) UDPDatagram {
uint16_t seq; // sequence number
int16_t sdata; // 16 bit integer data
int32_t idata; // 32 bit integer data
float fdata; // float data
uint16_t crc; // crc check
} udpDatagram = { 0, 10, 10, 3.14, 0 }; // initial values
void setup() {
Serial.begin(115200);
// Wait for serial port to connect. Needed for Leonardo only
while (!Serial)
;
delay(1000);
Serial.println();
Serial.println("ESP32 WiFi UDP client - send UDP datagrams to server");
WiFi.mode(WIFI_STA); // Connect to Wifi network.
WiFi.begin(ssid, pass);
Serial.println("");
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.print("\nserver IP address: ");
Serial.println(udpServer);
udp.begin(UDP_PORT);
Serial.print("server udp port ");
Serial.println(UDP_PORT);
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
Serial.println("Starting UDP");
Udp.begin(localPort);
Serial.print("Local port: ");
// Serial.println(Udp.localPort(localPort)); // bug
}
void loop() {
// generate crc check - in this case a simple checksum
udpDatagram.crc = 0;
Serial.println("Datagram data ");
for (int i = 0; i < sizeof(udpDatagram) - 2; i++) {
Serial.print((uint8_t)((uint8_t *)&udpDatagram)[i], HEX);
Serial.print(' ');
udpDatagram.crc += ((uint8_t *)&udpDatagram)[i];
}
OSCMessage msg("/pongo");
msg.add(65);
// msg.add("hello");
// msg.add(fnum);
Udp.beginPacket(outIp, outPort);
msg.send(Udp);
Udp.endPacket();
msg.empty();
// Send Packet to UDP server
udp.beginPacket(udpServer.toString().c_str(), UDP_PORT);
int len = udp.write((const uint8_t *)&udpDatagram, sizeof(udpDatagram));
udp.endPacket();
/*
Serial.print("\nudp datagram transmitted length ");
Serial.print(len);
Serial.print(" seq ");
Serial.print(udpDatagram.seq++);
Serial.print(" sdata ");
Serial.print(udpDatagram.sdata);
Serial.print(" idata ");
Serial.print(udpDatagram.idata);
Serial.print(" fdata ");
Serial.print(udpDatagram.fdata);
Serial.print(" crc = ");
Serial.println(udpDatagram.crc);
udpDatagram.crc = 0; // update data values for tests
udpDatagram.sdata += 10;
udpDatagram.idata += 25;
udpDatagram.fdata += 5.0f;
delay(10000);
*/
}