Hi, I have a Arduino Wifi101 and a Mega R3 and I am trying to just post one variable Ubidots and it works for the first or second post then stops. The code seems to run ok on the Arduino but for some reason stops midway through the posting process. Any thoughts would be greatly appreciated!!
Jon
Below is a sample of the serial output:
first successful post:
The full HTTP is:
POST /api/v1.6/collections/values/?force=true HTTP/1.1
Host: things.ubidots.com
User-Agent: Arduino-WiFi/1.1
X-Auth-Token: XXXXXXX
Connection: close
Content-Type: application/json
Content-Length: 58
[{"variable": "XXXXXXXX", "value":1.00}]
The TCP socket is opened
HTTP/1.1 200 OK
Server: nginx
Date: Tue, 29 Aug 2017 13:46:16 GMT
Content-Type: application/json
Transfer-Encoding: chunked
Connection: close
Vary: Accept-Encoding
Vary: Cookie
Allow: POST, OPTIONS
Unsuccessful post:
The full HTTP is:
POST /api/v1.6/collections/values/?force=true HTTP/1.1
Host: things.ubidots.com
User-Agent: Arduino-WiFi/1.1
X-Auth-Token: XXXXXX
Connection: close
Content-Type: application/json
Content-Length: 58
[{"variable": "XXXXXXX", "value":1.00}]
My code is below:
#include <UbidotsArduino.h>
#include <SPI.h>
#include <WiFi101.h>
#define ID "XXXXXX" // Put here your Ubidots variable ID
#define TOKEN "lXXXXXXX" // Put here your Ubidots TOKEN
char ssid[] = "XXXXX"; // your network SSID (name)
char pass[] = "XXXXX"; // your network password (use for WPA, or use as key for WEP)
int keyIndex = 0; // your network key Index number (needed only for WEP)
int status = WL_IDLE_STATUS;
Ubidots client(TOKEN);
#define ARRAYSIZE 8
int test[ARRAYSIZE] = {0,0,0,0,0,0,0,0};
void setup(){
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
// check for the presence of the shield:
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println("WiFi shield not present");
// don't continue:
while (true);
}
String fv = WiFi.firmwareVersion();
if (fv != "1.1.0") {
Serial.println("Please upgrade the firmware");
}
// attempt to connect to Wifi network:
while (status != WL_CONNECTED) {
Serial.print("Attempting to connect to SSID: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
status = WiFi.begin(ssid, pass);
// wait 10 seconds for connection:
delay(1000);
}
pinMode(2,INPUT);
}
void loop(){
for (int x = 0; x < 8; x++){
test[x] = digitalRead(2);
}
Serial.println(WiFi.status());
Serial.println(test[0]);
client.add(ID,test[0]);
client.sendAll();
delay(10000);
}