[SOLVED] Arduino Leonardo Eth (W5500 ethernet)

Good Day!
I am struggling to get my Arduino Leonardo Eth to upload to ubidots.

I have followed all the tutorials I could find but with no luck. Using the example from the library results in errors as I have to use #include ethernet2.h
I inititally worked off this example:

and this one:

http://help.ubidots.com/connect-your-devices/connect-the-adafruit-ethernet-featherwing-to-ubidots

I have 3 integers (volumes) that I need to post. What will be the easiest way of doing this?

Matt

Hello @Humm_Ind,

As you can noted in the README of the Ubidots Ethernet Library we metioned the following note:

IMPORTANT NOTE: The library was tested using a shield with W5100 chip Ethernet controller.” In order of this, if you are using another chip we can ensure the right functionality of it.

I recommend you find a WebClient example (which is easily to find on internet) for the Arduino Leonardo, make a test with the sample code to ensure the righ functionality of it. Then, once the first example code works properly modify the request establish in the sample to the Ubidots server.

For more information about the Ubidots REST API Reference, please see here.

All the best,
Maria C.

So I have go the Arduino successfully connected to the internet but I still cannot get my data sent, what am I missing?

void save_value(float v1Value, float v2Value)
{
  Serial.println("Sending data...");
  int num = 0;
  delay(2000);
 String varString = "{vol-1 : " + String(v1Value)+ " " + "vol-2 : " + String(v2Value); //build string for upload
 varString += "}";
  num = varString.length();
 
  Serial.println("Connecting...");
 
  if (client.connect(server,80)) {
    client.println("POST http://things.ubidots.com/api/v1.6/devices/jo-jo-tank-level/?token="+token);
    Serial.println("POST http://things.ubidots.com/api/v1.6/devices/jo-jo-tank-level/?token="+token);
    client.println("Host: things.ubidots.com");
    Serial.println("Host: things.ubidots.com");
    client.println("Content-Type: application/json");
    Serial.println("Content-Type: application/json");
    client.println("Content-Length: "+String(num));
    Serial.println("Content-Length: "+String(num));
    client.print(varString);
    Serial.print(varString+"n");
    delay(10000);
  }
  else
  {
    // if you didn't get a connection to the server:
    Serial.println("connection failed");
  }
 
  boolean sta = client.connected();
  Serial.println("Connection ["+String(sta)+"]");
  if (!client.connected())   {
   Serial.println();
   Serial.println("disconnecting.");
   client.stop();
  }
 
  Serial.println("Reading..");
  while (client.available()) {
    char c = client.read();
    Serial.print(c);
  }
  client.flush();
  client.stop();
  delay(10000);
}

Thanks so much!
Matt

Hello Matt,

As I can see in the code your are assigning the server in the request, also you missing HTTP/1.1" at the end of the first line plus another parameters. The request should be something like the one below:

  /* Make the HTTP request to the server*/
  _client.print(F("POST /api/v1.6/devices/"));
  _client.print(_deviceLabel);
  _client.println(F(" HTTP/1.1"));
  _client.println(F("Host: things.ubidots.com"));
  _client.print(F("User-Agent: "));
  _client.print(USER_AGENT);
  _client.print(F("/"));
  _client.println(VERSION);
  _client.print(F("X-Auth-Token: "));
  _client.println(_token);
  _client.println(F("Connection: close"));
  _client.println(F("Content-Type: application/json"));
  _client.print(F("Content-Length: "));
  _client.println(dataLen(body)); // payload length
  _client.println();
  _client.print(body); // payload to be sent
  _client.println();

To get a better understanding of how to build the POST request to Ubidots, I highly recommend you take a look of the POST method of the Arduino Ethernet Ubidots Library.

All the best,
Maria C.

Thank you so much for your help!

I got my project working!

Matt