-
Notifications
You must be signed in to change notification settings - Fork 7.6k
WifiUDPClient example: Keep receiving error could not send data #213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
UdpS.beginPacket(UdpS.remoteIP(), UdpS.remotePort()); |
And why not just Udp.beginPacket(UdpS.remoteIP(), UdpS.remotePort()); and so on, no need for two UDPs. Does not help you in any way in this case. UDP is not like TCP, there isn't really a connection that is kept ;) just you know where the packet should go and that's it. |
@me-no-dev I tried what you suggested in your first post and received the following error:
|
Try this: /**
* FreeIMU library serial communication protocol
*/
//These are optional depending on your IMU configuration
#include <ADXL345.h>
#include <HMC58X3.h>
#include <LSM303.h>
#include <LPS.h>
#include <L3G.h>
#include <ITG3200.h> //note LPS library must come before ITG lib
#include <bma180.h>
#include <MS561101BA.h> //Comment out for APM 2.5
#include <BMP085.h>
#include <I2Cdev.h>
#include <MPU60X0.h>
#include <AK8975.h>
#include <AK8963.h>
//#include <SparkFunLSM9DS1.h> // Uncomment for LSM9DS1
#include <SFE_LSM9DS0.h> // Uncomment for LSM9DS0 Chosse one or the othe ST IMUs
#include <BaroSensor.h>
//#include <AP_Baro_MS5611.h> //Uncomment for APM2.5
//These are mandatory
#include <AP_Math_freeimu.h>
#include <Butter.h> // Butterworth filter
#include <iCompass.h>
#include <MovingAvarageFilter.h>
#include <Wire.h>
#include <SPI.h>
//#define DEBUG
#include "DebugUtils.h"
#include "FreeIMU.h"
#include "DCM.h"
#include "FilteringScheme.h"
#include "RunningAverage.h"
//Intel Edison, Arduino 101, Arduino Due, Arduino Zero: no eeprom
#if defined(__SAMD21G18A__) || defined(__SAM3X8E__) || defined(__ARDUINO_ARC__) || defined(__SAMD21G18A__) || defined(ESP32)
#define HAS_EEPPROM 0
#else
#include <EEPROM.h>
#define HAS_EEPPROM 1
#endif
#define M_PI 3.14159
#define BaudRate 115200
float q[4];
int raw_values[11];
float ypr[3]; // yaw pitch roll
char str[128];
float val[14];
float val_array[21];
// Set the FreeIMU object and LSM303 Compass
FreeIMU my3IMU = FreeIMU();
//#include <ESP8266WiFi.h> //use for ESP8266
#include <WiFi.h> // use for ESP32
//#include <WiFiUdp.h>
#include <elapsedMillis.h>
elapsedMillis sendData1;
#define sendInterval 100
const char* ssid = "xxxxxx";
const char* password = "xxxxxxx";
WiFiUDP Udp;
static IPAddress remoteIp = 0;
static uint16_t remotePort = 0;
unsigned int localUdpPort = 4210; // local port to listen on
char incomingPacket[256]; // buffer for incoming packets
String payload;
//The command from the PC
char tempCorr;
String cmd;
void setup() {
Serial.begin(BaudRate);
Wire.begin();
//#if HAS_MPU6050()
// my3IMU.RESET();
//#endif
my3IMU.init(true);
Serial.println();
Serial.printf("Connecting to %s ", ssid);
// delete old config
WiFi.disconnect(true);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println(" connected");
Udp.begin(localUdpPort);
Serial.printf("Now listening at IP %s, UDP port %d\n", WiFi.localIP().toString().c_str(), localUdpPort);
WiFi.localIP().toString().c_str(), localUdpPort;
// LED
//pinMode(13, OUTPUT); //
pinMode(5, OUTPUT); //for eps32 thing from sparkfun
}
void serialPayloadPrint(float f) {
byte * b = (byte *) &f;
for(int i=0; i<4; i++) {
byte b1 = (b[i] >> 4) & 0x0f;
byte b2 = (b[i] & 0x0f);
char c1 = (b1 < 10) ? ('0' + b1) : 'A' + b1 - 10;
char c2 = (b2 < 10) ? ('0' + b2) : 'A' + b2 - 10;
payload += (c1);
payload += (c2);
}
}
void serialPayloadFloatArr(float * arr, int length) {
for(int i=0; i<length; i++) {
serialPayloadPrint(arr[i]);
payload += ",";
}
}
void loop() {
int packetSize = Udp.parsePacket();
if (packetSize)
{
// receive incoming UDP packets
remoteIp = Udp.remoteIP();
remotePort = Udp.remotePort();
Serial.printf("Received %d bytes from %s, port %d\n", packetSize, remoteIp.toString().c_str(), remotePort);
int len = Udp.read(incomingPacket, 255);
incomingPacket[len] = 0;
Serial.printf("UDP packet contents: %s\n", incomingPacket);
cmd = incomingPacket[0];
if(cmd=="v") {
sprintf(str, "FreeIMU library by %s, FREQ:%s, LIB_VERSION: %s, IMU: %s", FREEIMU_DEVELOPER, FREEIMU_FREQ, FREEIMU_LIB_VERSION, FREEIMU_ID);
Serial.print(str);
Serial.print('\n');
}
else if(cmd=="1"){
my3IMU.init(true);
}
else if(cmd=="2"){
my3IMU.RESET_Q();
}
else if(cmd=="g"){
my3IMU.initGyros();
//my3IMU.zeroGyro();
}
else if(cmd=="t"){
//available opttions temp_corr_on, instability_fix
my3IMU.setTempCalib(1);
}
else if(cmd=="f"){
//available opttions temp_corr_on, instability_fix
my3IMU.initGyros();
my3IMU.setTempCalib(0);
}
}
if(!remotePort){
//nobody have connected yet
return;
}
//if(sendData1 > sendInterval){
float val_array[20] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
my3IMU.getQ(q, val);
val_array[15] = my3IMU.sampleFreq;
//my3IMU.getValues(val);
val_array[7] = (val[3] * M_PI/180);
val_array[8] = (val[4] * M_PI/180);
val_array[9] = (val[5] * M_PI/180);
val_array[4] = (val[0]);
val_array[5] = (val[1]);
val_array[6] = (val[2]);
val_array[10] = (val[6]);
val_array[11] = (val[7]);
val_array[12] = (val[8]);
val_array[0] = (q[0]);
val_array[1] = (q[1]);
val_array[2] = (q[2]);
val_array[3] = (q[3]);
//val_array[15] = millis();
val_array[16] = val[9];
val_array[18] = val[11];
val_array[19] = val[12];
#if HAS_PRESS()
// with baro
val_array[17] = val[10];
val_array[13] = (my3IMU.getBaroTemperature());
val_array[14] = (my3IMU.getBaroPressure());
#elif HAS_MPU6050()
val_array[13] = (my3IMU.DTemp/340.) + 35.;
#elif HAS_MPU9150() || HAS_MPU9250()
val_array[13] = ((float) my3IMU.DTemp) / 333.87 + 21.0;
#elif HAS_LSM9DS0()
val_array[13] = 21.0 + (float) my3IMU.DTemp/8.; //degrees C
#elif HAS_ITG3200()
val_array[13] = my3IMU.rt;
#elif HAS_CURIE()
val_array[13] = (my3IMU.DTemp/512.0) + 23.0;
#endif
payload = "";
serialPayloadFloatArr(val_array, 20);
payload += "\r\n";
Udp.beginPacket(remoteIp, remotePort);
Udp.print(payload);
Udp.endPacket();
sendData1 = 0;
//}
} |
Ok. Gave it a try and it worked for a few data transfers and then it gave me about 20 or 30 of the following:
and then froze up. By the way are the following lines really 0: or am I suppose to put mine own in. PS. if I leave them as it it won't compile complains about the IPaddress. |
By the way I am using a Sparkfun ESP32 Thing with Arduino IDE 1.8.1 on a windows 10 machine. I am new to wifi so pardon my ignorance. I did get the same sketch working on an LinkNode D1 which is an ESP8266 with no problem so I am not sure where the problem lies. |
well you are running on a two core 240 MHz CPU :) and you are sending packet after packet, which leaves little time for the other core to do it's chores. Try putting a delay of 1ms or so at the end of the loop. As for |
Thanks for the info on chip and the possible race conditions. I did the following:
and added a delay of 10ms at the end of the loop. It sends back 3 packets after I transmits from the pc and then I get the error:
I also tried to set
|
@me-no-dev I have a question that may be related to this. what I am reading is accel, gyro and magnetomer readings via i2c from a Adafruit lsm9ds0. When I do a test of just reading raw data (no wifi) the values are fixed no change ( using the Sparkfun lib for the lsm9ds0). If I run the same test using a teensy 3.6 reads values no problem. I am setting the i2c bus to 400khz with the setclock function. |
I got the sketch to work to a point. But to do that I had to edit a couple of lines:
and It does work for quite awhile but i keep getting the
message. I have a tried delays of 1, 10, 20 and 100ms. It seems for me 100 works well. There should be a way to test if the chip is ready to send the message. If not just wait. Don't know if it is possible. |
you are probably hitting another bug. Watch for the update that I will push tomorrow with updated libs and give it another go |
Will check it tomorrow thanks |
Downloaded the changes that you made and now having a whole different set of errors; Case 1, ESP32 Dev module selected: FAILS
From the ESP Debug tool:
Case 2. Since I am using a Sparkfun ESP32Thing I selected that board. FAILS
From Decoder:
Case 3, UDPCient Example: FAILS:
Decoder:
This is leading me to believe that there is some bug in the library pushes (9:13 am, Monday)
|
all errors point to the same thing. I will do a test case and report to idf, but for you, just remove the first call to WiFi.begin(); and then to AiFi.disconnect(true); and your wifi will work as expected. Calling WiFi.begin(ssid,pass) already overwrites the default setting. |
Unrelated note... I think the exception decoder grabs a few values from the bootloader output (like 0x40080000). |
@igrr great for noticing that! Will adjust the plugin in the next update. |
Check the sketches and there is no WiFi.begin() only WiFi.begin(ssid,pass). I commented out the lines for WiFi.disconnect(true) and am still receiving the same errors. Used the UDP example. |
Ok. Decided to run the WifiScan example and am getting similar errors.
Same type of error. |
this is my output of the WiFi scan sketch (no modifications)
Also see if it might be connected to this |
Yep erasing the flash seemed to do the trick to get rid of the errors I posted earlier today. |
everything working now? |
Know you don't want to hear this but not really. Since er AZ see false I can connect but I keep getting different errors. I tried a couple of different sketches. I have to lay ou a couple of cas es S for you but decided to take a break .. am getting a headache. Smile. Will get back to it tonight. |
Ok Here it goes. I had written a simple test sketch based on the example to send and receive from Network like the example sketch:
Loads fine and connects right away. I send one message and it acknowledges receipt. When I send another message it crashed and hangs. This is the only thing that is returned on the second attempt:
If I hit the reset never wants to reconnect. Have to unplug. When I do it again same thing happens. Next test is with the full sketch that we worked on earlier that you modified:
Then error message keeps repeating. If I reset it will reconnect but just hangs with no error messages (no data is received). If I power off/power on it will respond with an acknowledge but hangs with no data returned. I checked to make sure that connections are good and the ESP32 recognizes the I2C addresses. When I remove the setClock(400000L) call same error happens. Sorry to cause you such problems. Thanks for all your help and patience. |
Just one more bit of info. I tried running the same sketch on a 8266 and it crashed as well. I have a open issue over on that side as well: [https://github.com/esp8266/Arduino/issues/2983]. May be related - not sure why when I did have it working before. Beginning to wonder if it an i2c issue. |
copy-pasted the sketch above, bombarded with packets, no issue at all. This is something on your end :) not necessarily the ESP. Could be your network/AP. I tested with 3 devices ;) |
Do you have any suggestions on how to figure it what the problem is. By the way what board are you using. |
@me-no-dev. Just wanted to let you know I picked up a different board (ESP32 dev board by Onehorse on Tindie, it uses dout and DFU) and uploaded the same sketch and it works fine with no problem. I tried it again on the ESP32 Thing by Sparkfun and it hangs after it sends back about 10-20 packets. |
I think I might have the exact same problem as @me-no-dev described. I'll try to upload the code to another ESP32 dev board and see. |
I apologize for posting on this old and closed issue, but... |
Same here before I switched boards. Pretty much gave up on the sparkfun board. |
sparkfun use 26MHz crystals and all other boards use 40MHz... maybe that is the issue (somehow) |
I tired running the sample WifiUDPclient sketch and I keep receiving the following error message:
I also receive a similar error message from a custom sketch that works fine with a ESP8266. I receive on 4210 and send on 4211. I listed that code for your reference.
Any help would be appreciated.
Mike
The text was updated successfully, but these errors were encountered: