Adding another row in google spreadsheet using pushingbox.

Hi all,

I want to log two inputs to google spreadsheet using Arduino. I have been able to log the first input, however I cannot figure out on how to add the 2nd row.

The code is below. Do I have change anything? Please do comment on it. Thank you.

void tempData(){ tdata+=""; tdata+="GET /pushingbox?devid=vBB839DED2B03F29&tempData="; //GET request query to pushingbox API tdata+=DHT.temperature; tdata+=" HTTP/1.1";

} void humData(){ hdata+=""; hdata+="GET /pushingbox?devid=vBB839DED2B03F29&humData="; //GET request query to pushingbox API hdata+=DHT.humidity; hdata+=" HTTP/1.1"; } void sendTempData(){ Serial.println("connected"); client.println(tdata); client.println("Host: api.pushingbox.com"); client.println("Connection: close"); client.println(); }

void sendHumData(){ Serial.println("connected"); client.println(hdata); client.println("Host: api.pushingbox.com"); client.println("Connection: close"); client.println();

}

Do I have change anything?

Not if you are happy with the results you are getting. You aren't, are you?

What happens the second time you call tempData() or humData()? What is in tdata or hdata after that happens?

The tdata += ""; looks wrong to me. I'd have written tdata = ""; myself, to replace what was there, instead of adding to what was there.

Why not send the temperature and humidity data in one step?

Thanks for your reply.

the tdata and hdata will be cleared once the data is sent to google spreadsheet.

The full code is here:

#include <dht.h>
#include <SPI.h>
#include <WiFi.h>

#define dht_dpin A0

dht DHT;

char ssid = “”; // the name of your network
int status = WL_IDLE_STATUS; // the Wifi radio’s status
char server = “api.pushingbox.com”; //pushingbox API server
WiFiClient client; //define ‘client’ as object
String tdata; //GET query with data
String hdata; //GET query with data
boolean connection = false;

void setup() {
//Initialize serial and wait for port to open:
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 open SSID: ");
Serial.println(ssid);
status = WiFi.begin(ssid);

// wait 10 seconds for connection:
delay(10000);
}

// you’re connected now, so print out the data:
Serial.print(“You’re connected to the network”);

}

void loop()
{
DHT.read11(dht_dpin);
delay(5000);
tempData(); //packing GET query with data
humData();//packing Get query with data
Serial.println(“connecting…”);

if (client.connect(server, 80))
{
sendData();
connection = true; //connected = true
}
else
{
Serial.println(“connection failed”);
}
// loop
while(connection)
{
if (client.available())
{
char c = client.read(); //save http header to c
Serial.print(c); //print http header to serial monitor
}
if (!client.connected())
{
Serial.println();
Serial.println(“disconnecting.”);
Serial.print("Current temperature = ");
Serial.println(DHT.temperature); //print sent value to serial monitor
Serial.print("Current humidity = ");
Serial.println(DHT.humidity);
client.stop();
connection = false;
tdata = “”; //data reset
hdata = “”; //data reset

}
}
delay(5000); // interval
}

void tempData(){
tdata+="";
tdata+=“GET /pushingbox?devid=vBB839DED2B03F29&tempData=”; //GET request query to pushingbox API
tdata+=DHT.temperature;
tdata+=" HTTP/1.1";

}
void humData(){
hdata+="";
hdata+=“GET /pushingbox?devid=vBB839DED2B03F29&humData=”; //GET request query to pushingbox API
hdata+=DHT.humidity;
hdata+=" HTTP/1.1";
}
void sendData(){
Serial.println(“connected”);
client.println(tdata);
client.println(hdata);
client.println(“Host: api.pushingbox.com”);
client.println(“Connection: close”);
client.println();
}

I have not been able to log the value from DHT.humidity. Temperature log is fine.

You need to make 2 complete HTTP requests, including the ‘Host’ and ‘Connection’ headers, but especially including the empty line. Right now, what you send is:

GET /bla/tempdata HTTP/1.1
GET /bla/humdata HTTP/1.1
Host: bla
Connection: close
<empty line>
  • Maybe you can use ‘Connection: keep-alive’ (only on the 1st one?) to send both requests through the same connection.

  • Maybe you have to wait for the connection to close, then re-open it for the 2nd request.

  • Maybe you can use 2 wifi clients: 1 per request.

  • Or maybe you can construct a single request with both pieces of data in it:

GET /pushingbox?devid=vXYZ123XYZ123ABCD&tempData=111&humData=222 HTTP/1.1
while(connection)
  {
    if (client.available())
    {
    char c = client.read(); //save http header to c
    Serial.print(c); //print http header to serial monitor
    }
    if (!client.connected())
    {

How many characters of the server response are you reading? Why are you need reading ALL of them?

You need a while(client.connected()) loop containing a while(client.available()) loop to read ALL of the server's response before disconnecting, inside an if test (NOT a while loop) to see if connected.

Plus what Jobi-Wan said...