Hi everyone, I am using pico with W850 io. I am using earlephilhowercore. I am using W5500 with them and I am using this library for it khoih-progEthernet.
I am using two cores of pico. One is running stepper, loadcell etc. The other core is using only ethernet for get request and post request.
Everything is working fine but after hours (it is not stable maybe 1 maybe 3 hour or maybe 10 minute, it gives statusCode -2 error and I can't use ethernet anymore without unplugged the pico from computer.
So what is the problem ? I really don't understand why it is happening.
// This call was made when the EthernetHttpClient class wasn't expecting it
// to be called. Usually indicates your code is using the class
// incorrectly
static const int HTTP_ERROR_API = -2;
I am initializing ethernet like this:
int port = 80;
EthernetClient client;
EthernetHttpClient httpClient(client, serverAddress, port);
void setup1() {
Serial.begin(115200);
while (!Serial);
pinMode(USE_THIS_SS_PIN, OUTPUT);
digitalWrite(USE_THIS_SS_PIN, HIGH);
#define USE_THIS_SS_PIN 17 // For E.Philhower core
Ethernet.init (USE_THIS_SS_PIN);
uint16_t index = millis() % NUMBER_OF_MAC;
Ethernet.begin(mac[index], 1000);
}
I am using four pins of ethernet ;
2.1 SPI0 (default)
| W5500 | <---> | RP2040 |
|---|---|---|
| MOSI | <---> | GP19 |
| MISO | <---> | GP16 |
| SCK | <---> | GP18 |
| SS | <---> | GP17 |
| GND | <---> | GND |
| VCC | <---> | +3.3V |
with these connection.
I really couldn't find why is this happening. Any help would be greatly appreciated . Thank you
My core 1 get and post codes
if ((setCurrentTime - setPreviousTime >= onceAday)) //For update time everyday;
{
setPreviousTime = setCurrentTime;
String get_path = "/todos/1";
httpClient.get(get_path);
int statusCode = httpClient.responseStatusCode();
if (statusCode == 200)
{
String response = httpClient.responseBody();
StaticJsonDocument<200> doc;
deserializeJson(doc, response);
int user_id = doc["userId"];
Serial.println(user_id);
}
else
{
onceAday = 2000;
}
}
unsigned long currentMillisGet_machine1 = millis();
if (currentMillisGet_machine1 - previousMillisGet_machine1 >= 400)
{
previousMillisGet_machine1 = currentMillisGet_machine1;
if (startHttpGetRequest_machine1 && isLoadcell_machine1)
{
Serial.println(full_id_machine1);
if (isLoadcell_machine1)
{
String get_path = "/todos/" + full_id_machine1;
Serial.println(get_path);
httpClient.get(get_path);
int statusCode = httpClient.responseStatusCode();
Serial.print("Status code: ");
Serial.println(statusCode);
if (statusCode == 200)
{
String response = httpClient.responseBody();
Serial.print("Response: ");
Serial.println(response);
StaticJsonDocument<200> doc;
deserializeJson(doc, response);
machine1 = doc["id"];
Serial.println(machine1);
}
startHttpGetRequest_machine1 = false;
}
}
}
unsigned long currentMillisPost_machine2 = millis();
if (currentMillisPost_machine2 - previousMillisPost_machine2 >= 700)
{
previousMillisPost_machine2 = currentMillisPost_machine2;
if (startHttpPostRequest_machine2 && isLoadcell_machine2)
{
String post_path = "/todos/1";
String contentType = "application/json";
String post_data = "[{\"userId\":" + String(id_machine2) + "},]";
Serial.println(post_data);
httpClient.post(post_path, contentType, post_data);
int statusCode = httpClient.responseStatusCode();
Serial.println(statusCode);
if (statusCode == 200)
{
String response = httpClient.responseBody();
Serial.println(response);
}
startHttpPostRequest_machine2 = false;
machine2 = 0;
id_machine2 = "";
}
}```