[un/loquer] ¿Cómo hacer un post a un API desde el ESP8266?

brolin brolin108 en gmail.com
Vie Mar 25 22:09:03 UTC 2016


Hola,

estuvimos trabajando con Uber en estos días pillando cómo se hace un post a
un API. Lo estábamos intentando con ubidots.

Este curl : curl -XPOST -H 'Content-Type: application/json;' -H
'X-Auth-Token: AUTH_TOKEN' -d '{"value": 23}'
http://things.ubidots.com/api/v1.6/variables/ID_VARIABLE/values

en arduino se escribe así:

  String url = "http://things.ubidots.com/api/v1.6/variables/"
ID_VARIABLE "/values";
  http.begin(url);
  http.addHeader("Content-Type", "application/json");
  http.addHeader("X-Auth-Token", AUTH_TOKEN);
  int content_length =0;
  String payload = String("{ \"value\": " + String(millis()/1000) + "}");
  //content_length = payload.length();
  //http.addHeader("Content-Length ", String(content_length));
  int httpCode = http.POST(payload);
  if(httpCode > 0) {
    String payload = http.getString();
    Serial.println(payload);
  }
  else {
    Serial.print("[HTTP] failed, error:
");Serial.println(http.errorToString(httpCode).c_str());
  }
  http.end();

El código se subió acá https://github.com/unloquer/postUbidots/

Por otro lado Uber diseñó unas tarjeticas para el ESP, un nodemcu local :D
Hay que mandarlas a hacer a colcircuitos


Saludos,
-
b
------------ próxima parte ------------
Se ha borrado un adjunto en formato HTML...
URL: <https://lists.aktivix.org/pipermail/unloquer/attachments/20160325/774e5a76/attachment.html>


Más información sobre la lista de distribución unloquer