void processing_data(uint8_t *data, uint16_t len) {
if ( debugging && // IGNORE SPECIFIC PACKETS WHILE DEBUGGING, GOOD FOR PREVENTING FLOODING WHILE DEBUGGING
(((uint16_t)(data[0] << 8) | data[1]) != 0x8783 ) &&
(((uint16_t)(data[0] << 8) | data[1]) != 0x7E7E )
) {
[B][COLOR="#0000FF"]// for ( uint16_t i = 0; i < len - 1; i++ ) {
// Serial.print(data[i], HEX); Serial.print(" "); // DEBUGGING
// } Serial.println();[/COLOR][/B]
}
strncpy( incomingPacket, packet.data(), packet.length());
error: invalid conversion from 'uint8_t* {aka unsigned char*}' to 'const char*' [-fpermissive]
strncpy( incomingPacket, packet.data(), packet.length());
//#include <ESP8266WiFi.h>
//#include <WiFiUdp.h>
#include <teensquitto.h>
#include <IPAddress.h>
//Teensquitto setup for UDP send and receive
teensquitto Udp = teensquitto("WiFiUdp", &Serial1);
teensquitto wifi = teensquitto("WiFi", &Serial1);
IPAddress ip(192, 168, 1, 162);
IPAddress gate(192, 168, 1, 1);
IPAddress sub(255, 255, 255, 0);
const char* ssid = ".....................";
const char* password = "....................";
//WiFiUDP Udp;
unsigned int localUdpPort = 4210; // local port to listen on
char incomingPacket[255]; // buffer for incoming packets
char replyPacket[] = "Hi there! Got the message :-)"; // a reply string to send back
void setup()
{
Serial.begin(115200);
Serial1.begin(2000000);
Serial.println();
ESP.onDetect([]() {
wifi.mode(WIFI_STA);
wifi.begin(ssid, password);
wifi.waitForConnectResult();
wifi.config(ip, gate, sub);
Serial.printf("Connecting to %s ", ssid);
wifi.begin(ssid, password);
while (wifi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println(" connected");
}); // end of onDetect callback
Udp.begin(localUdpPort);
Serial.printf("Now listening at IP %s, UDP port %d\n", wifi.localIP().toString().c_str(), localUdpPort);
}
void loop()
{
int packetSize = Udp.parsePacket();
if (packetSize)
{
// receive incoming UDP packets
Serial.printf("Received %d bytes from %s, port %d\n", packetSize, Udp.remoteIP().toString().c_str(), Udp.remotePort());
int len = Udp.read((unsigned char *)incomingPacket, 255); [COLOR="#FF0000"]//had to use this casting to get it to compile.......[/COLOR]
if (len > 0)
{
incomingPacket[len] = 0;
}
Serial.printf("UDP packet contents: %s\n", incomingPacket);
// send back a reply, to the IP address and port we got the packet from
Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
Udp.write(replyPacket,len);
Udp.endPacket();
}
wifi.events();
}
void serialEvent1() {
wifi.events();
}
virtual size_t read(uint8_t* buf, size_t size)
// Read up to len bytes from the current packet and place them into buffer
// Returns the number of bytes read, or 0 if none are available
virtual int read(unsigned char* buffer, size_t len);
// Read up to len characters from the current packet and place them into buffer
// Returns the number of characters read, or 0 if none are available
virtual int read(char* buffer, size_t len) { return read((unsigned char*)buffer, len); };
if (packetSize)
{
read message
send different message
}
//Teensquitto setup for UDP send and receive
teensquitto Udp = teensquitto("WiFiUdp", &Serial1);
teensquitto UdpS = teensquitto("WiFiUdp", &Serial1);
unsigned int localUdpPort = 4210; // local port to listen on
unsigned int localUdpPortS = 3333; // local port to listen on
Udp.begin(localUdpPort);
UdpS.begin(localUdpPortS);
int packetSize = Udp.parsePacket();
if (packetSize)
{
// receive incoming UDP packets
Serial.printf("Received %d bytes from %s, port %d\n", packetSize, Udp.remoteIP().toString().c_str(), Udp.remotePort());
int len = Udp.read((unsigned char *)incomingPacket, 255);
if (len > 0)
{
incomingPacket[len] = 0;
}
Serial.printf("UDP packet contents: %s\n", incomingPacket);
packetSize = 0;
}
// send back a reply, to the IP address and port we got the packet from
UdpS.beginPacket(UdpS.remoteIP(), UdpS.remotePort());
UdpS.write(replyPacket,30);
UdpS.endPacket();
Yeah now that you mention it you did - sorry - I forgot.Hope it clears that up, but I’m pretty sure I told you that when you played with WiFiClient last time
I will double check... don't think I did that with the new version of the core.did you increase serial1.c buffer like i mentioned earlier? 64 is too small
14550 WiFiUdp, 14555 AsyncUDPwhats on that port? udp?
Will give it a try.v2 low bandwidth mode in tools menu,
Nopedid you test the code directly on esp to replicate?