6 years, 8 months ago.

NucleoL476 + IDW01M1 Wifi send data to Ubidots

Hello,

I'm trying to post data to Ubidots Cloud service (1 variable)

I'm using NucleoL476 and X-Nucleo-IDW01M1 wifi shield and nothing is udpated to Ubidots. When I try same command API with hurl.it, It working. Socket.recv() return -3001 ?

Here my terminal results:

######## IDW01M1 NetworkSocketAPI TCP Client Ubidots Example

Connecting to AP

Now connected

IP address is: 192.168.0.17

MAC address is: 00:80:E1:B7:C5:D8

things.ubidots.com resolved to: 50.23.124.68

Socket connected

{"value": 2114}

POST /api/v1.6/variables/5997efbdc03f971ca757920a/values HTTP/1.1

Content-Type: application/json

Content-Length: 15

X-Auth-Token: A1E-B0I6Hzcqxxtl0ecHPOrApvvkoABQE8

Host: things.ubidots.com

{"value": 2114}

Send data to Ubidots

Received -3001 ##########

Code is attached /media/uploads/rrom/main.cpp

Thanks for help.

1 Answer

6 years, 7 months ago.

I've just tested your request with mbed-http and that works fine for me (although I get a 404, I guess the thing has been removed):

HttpRequest* get_req = new HttpRequest(network, HTTP_POST, "http://things.ubidots.com/api/v1.6/variables/5997efbdc03f971ca757920a/values");
get_req->set_header("Content-Type", "application/json");
get_req->set_header("X-Auth-Token", "A1E-B0I6Hzcqxxtl0ecHPOrApvvkoABQE8");

const char* buffer = "{\"value\": 98}";

HttpResponse* get_res = get_req->send(buffer, strlen(buffer));
if (!get_res) {
    printf("HttpRequest failed (error code %d)\n", get_req->get_error());
    return 1;
}

printf("\n----- HTTP GET response -----\n");
dump_response(get_res);

delete get_req;

Could you try that? HTTP is notoriously harder than it looks at first glance even though your HTTP request seems valid.

Hello Jan,

First of all a big thank you for your answer.

Have you tested this solution with the same hardware as me? Before testing your code, do I need to keep the Socket library?

Could you share the whole of your main.cpp?

Thank you.

posted by rom r 30 Aug 2017

I tested with ODIN-W2 and K64F boards, unfortunately I don't have IDW01M1 shield on hand, but -3001 is often a sign that the server is still waiting for the request, and then the socket times out, so it's probably a malformed HTTP request. I've put my main.cpp here, hope it helps.

posted by Jan Jongboom 30 Aug 2017