Using 2 core with one ethernet

Hi everyone, I am using raspberry pi pico with earle's pico core earlephilhowercore. I am using W5500 with them and I am using this library for it khoih-progEthernet. I hava a lot of code like 1000+ line. I am doing http get and post request and then doing some stuff with these datas. I initialize W5500 ethernet on core 0. Here is my code ;

void setup()
{
  uint16_t index = millis() % NUMBER_OF_MAC;
  Ethernet.begin(mac[index], 1000);
 }
 void loop()
 {
  Serial.println("making GET request");
  
  int statusCode = httpClient.responseStatusCode();
  
  String response = httpClient.responseBody();
 .
 .
 .
 
 }
 void setup1()
{
 
 }
 void loop1()
 {
  Serial.println("making GET request");
  
  int statusCode = httpClient.responseStatusCode();
  
  String response = httpClient.responseBody();
 .
 .
 .
 }

As I said, I can only use ethernet to activate in 1 core. When I activate it in 2 cores, an error occurs.

uint16_t index = millis() % NUMBER_OF_MAC;
  Ethernet.begin(mac[index], 1000);

When I start the code, void loop1 can http request too but after a bit, W5500 give code -2 and -3. Errors :

// Could not connect to the server
static const int HTTP_ERROR_CONNECTION_FAILED = -1;
// 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;
// Spent too long waiting for a reply
static const int HTTP_ERROR_TIMED_OUT = -3;
// The response from the server is invalid, is it definitely an HTTP
// server?
static const int HTTP_ERROR_INVALID_RESPONSE = -4;

So my question is, is this error appears because I am using ethernet on core 1 without initialize it ?

Thank you.

You only have hardware for one connection, initializing a second connection is thus not possible. You may have luck running two clients on the same connection, though..

Thank you for yyour answer. I think, I need to use ethernet stuff in core 0 then other things core 1. Is it solve the problem ?

If it works, how can I reach http get responses. While defining global variables ?

I mean if I use ethernet on core0, how can core1 reach http valeus ?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.