Friends,
I am attempting to post data to a google sheet from a particle device. I currently have a ambient temp & humidity sensor and a water temp sensor and want to have that data post to a google doc every 2 hours. I only have three values right now but I am wanting to make it easy to add more values if at all possible.
This is my first try interfacing with webhooks so please be brutally honest with what i am doing wrong. I have found a number of helpful tutorials that have helped me build the webhook but when the Particle.publish(data,dataStr)
publishes i get an error in the particle logs(screenshot below).
The tutortial i found the most helpful, and followed the most closley is this one https://www.hackster.io/gusgonnet/pushing-data-to-google-docs-02f9c4
It was very helpful but i was (still am) confused on the formatting of the data in my particle web ide code, and how that all interacts with the JSON and the google script code.
I don’t want to use any third party services, as i want to keep it as simple as possible. Here is a screen shot of the webhook and where i think I am wrong.
I currently have no code in the google sheet, i only have it deployed as a web app,
here is the particle code i am using.
// This #include statement was automatically added by the Particle IDE.
#include "DS18.h"
// This #include statement was automatically added by the Particle IDE.
#include <Adafruit_DHT.h>
// This #include statement was automatically added by the Particle IDE.
#include <elapsedMillis.h>
#define ambientPin D4
#define DHTTYPE DHT11
#define SprayPin D2
#define WaterTempPin D3
/****************************INPUTS*****************************************/
int32_t OnTime = 10000; //Time in milliseconds, how long you want to spray for
int32_t OffTime = 60000; //Time in milliseconds, how long to be off in between cycles
/***************************************************************************/
elapsedMillis timer0; // a running timer to keep track of ON time
bool Spraying = false; // a flag used to tell us if the pump is on
int32_t mainOnTime = -1;
int32_t mainOffTime = -1;
int32_t resetTime = 40*24*3600*1000;
double ambTempF = -1; //Setting up ambient sensor
double ambHumid = -1;
DHT dht(ambientPin, DHTTYPE);
double waterTempF=-1; //Setting up water temp sensor
double waterTempC=-1;
DS18 sensor(WaterTempPin);
String resultstr=String(64); // String to be used in the particle publish
void setup() {
Serial.begin(9600);
pinMode(SprayPin, OUTPUT); // Telling the controller this pin will be used as a Digital output
pinMode(ambientPin, INPUT);
digitalWrite(SprayPin, LOW); // On start up keep output off
pinMode(WaterTempPin,INPUT);
Particle.variable("waterTempF",waterTempF);
Particle.variable("AmbientTemp", ambTempF);
Particle.variable("Humidity", ambHumid);
}
void loop() {
ambTempF = dht.getTempFarenheit(); //fetching ambient temp and humidity from DH11
ambHumid = dht.getHumidity();
//WATER TEMP SENSOR
if(sensor.read()){
waterTempF=sensor.fahrenheit();
waterTempC=sensor.celsius();
//Serial.println();
//Serial.printf("Temperature %.2f C %.2f F ", waterTempC,waterTempF );
// Serial.println(waterTempC);
//Serial.println(waterTempF);
}
if(timer0%5000==0){
//Serial.println("Temp: ");
//Serial.println(ambTempF);
//Serial.println("Humidity: ");
//Serial.println(ambHumid);
//resultstr = String(ambTempF) +" "+ String(ambHumid);
//Serial.println(resultstr);
Particle.publish("googleDocs", "{\"my-name\":\"" + resultstr + "\"}", 60, PRIVATE);
//Particle.publish("googleDocs", resultstr, 60, PRIVATE);
} //used for doing things at a certain time interval
if(!Spraying){ // turns the spray pin on
if(timer0-mainOffTime>OffTime){
Spraying=true;
spayersOn();
}
}
if(Spraying){ // turns the sprayers off
if(timer0-mainOnTime>OnTime){
Spraying=false;
spayersOff();
}
}
}
void spayersOn(){
digitalWrite(SprayPin,HIGH);
mainOnTime=timer0;
}
void spayersOff(){
digitalWrite(SprayPin,LOW);
mainOffTime=timer0;
}
any insight or good resources on how to pass data from server to server is greatly appreciated.