I am working on a sketch where the current time and date is posted to Firebase when motion is detected by a PIR motion sensor. Currently nothing is being posted to Firebase when I run the sketch also I am not sure if I am getting the current date and time correctly and storing it in the variable "result". Source code below.
#include <Process.h>
// Pin
int pir_pin = 8;
void setup()
{
Bridge.begin(); // Initialize the Bridge
pinMode(pir_pin,INPUT);
}
void loop()
{
if (digitalRead(pir_pin) == true) {
String result;
Process time;
time.begin("date");
time.addParameter("+%D-%T");
time.run();
while(time.available()>0) {
char c = time.read();
if(c != '\n')
result += c;
}
Process p;
p.runShellCommand("curl -k -X POST https://MY_ACCOUNT.firebaseio.com/Activity.json -d '{ \"Motion Detected At\" : " + String(result) + "}'");
while(p.running());
delay(2000);
}
}
Fiscuries:
I am not sure if I am getting the current date and time correctly and storing it in the variable "result".
Then I would think the first step is to verify that you're getting what you hope to get. Set up the Serial port or Console port, and print out the value that you're getting. Male sure to print some character (like a quote) immediately before and after the value, as I suspect you may be getting a line terminator at the end of the string - when you combine that with the rest of your curl command string, it may be messing up your command line.
Then, try building your curl command string as a String object and print it out to see if it's being formatted as you expect.
Finally, take the curl command string, and manually type it into the Yun's SSH command line and try to run it. If it doesn't work, you should get some meaningful error messages. If it doesn't work at the command line, it certainly won't work from within the sketch.
Those are the debugging steps I would try...