boolean save_value(String valor,String idvariable)//Send value to Ubidots { int cbRead=0; String var = "{\"value\":"+ valor + "}"; int num = var.length(); String le = String(num); String message = "POST /api/v1.6/variables/"+idvariable+"/values HTTP/1.1\nContent-Type: application/json\nContent-Length: "+le+"\nX-Auth-Token: "+token+"\nHost: app.ubidots.com\n\n"+var+"\n\n"; byte rgbWriteStream[message.length()] ; message.getBytes(rgbWriteStream,message.length() + 1); int cbWriteStream = sizeof(rgbWriteStream); state_machine(rgbWriteStream,cbWriteStream); return true; } boolean state_machine(byte rgbWriteStream[], int cbWriteStream)//Handle the TCP connection { IPSTATUS status; for(;;) { int cbRead = 0; switch(state) { case CONNECT: if(WiFiConnectMacro()) { Serial.println("WiFi connected"); deIPcK.begin(); state = TCPCONNECT; } else if(IsIPStatusAnError(status)) { Serial.print("Unable to connection, status: "); Serial.println(status, DEC); state = CLOSE; } break; case TCPCONNECT: if(deIPcK.tcpConnect(szIPServer, portServer, tcpSocket)) { Serial.println("Connected to server."); state = WRITE; } break; // write out the strings case WRITE: if(tcpSocket.isEstablished()) { tcpSocket.writeStream(rgbWriteStream, cbWriteStream); state = CLOSE; tStart = (unsigned) millis(); } break; case CLOSE: tcpSocket.close(); Serial.println("Closing TcpClient, Done with sketch."); state = DONE; break; case DONE: state = TCPCONNECT; return cbRead; default: break; } // keep the stack alive each pass through the loop() DEIPcK::periodicTasks(); } }