Go Down

Topic: [Solved]Arduino yun mini + firebase, retrieve data from firebase (Read 262 times) previous topic - next topic

nnitgd

Hi, I have a question about communication between Yun and Firebase.

I success upload a random value from arduino Yun to Firbase databse with code as below.

Code: [Select]


#include <Process.h>

void setup()
{
  Bridge.begin();   // Initialize the Bridge
}

void loop()
{
  // Simulate Get Sensor value
  int sensor = random(10, 20);
 
  Process p;
  p.runShellCommand("curl -k -X POST https://[my project name].firebaseio.com/temperature.json -d '{ \"value\" : " + String(sensor) + "}'"); 

  while(p.running());
  delay(500);               
 

}


Then, how can I retrieve the value from firebase?

nnitgd

I try to using "process" in the https://www.arduino.cc/en/Guide/ArduinoYun#toc17
I chage "http://arduino.cc/asciilogo.txt" to "https://[my project name].firebaseio.com/temperature.json"
But serial print nothing.


Code: [Select]


#include <Process.h>

void setup() {
  // Initialize Bridge
  Bridge.begin();

  // Initialize Serial
  Serial.begin(9600);

  // Wait until a Serial Monitor is connected.
  while (!Serial);

  // run various example processes
  runCurl();
}

void loop() {
  // Do nothing here.
}

void runCurl() {
  // Launch "curl" command and get Arduino ascii art logo from the network
  // curl is command line program for transferring data using different internet protocols
  Process p;        // Create a process and call it "p"
  p.begin("curl");  // Process that launch the "curl" command
  p.addParameter("https://[my project name].firebaseio.com/temperature.json"); // Add the URL parameter to "curl"
  p.run();      // Run the process and wait for its termination

  // Print arduino logo over the Serial
  // A process output can be read with the stream methods
  while (p.available()>0) {
    char c = p.read();
    Serial.print(c);
  }
  // Ensure the last bit of data is sent.
  Serial.flush();
}



When I type https://[my project name].firebaseio.com/temperature.json in the internet browser.
i can get
Code: [Select]

{"-Kj8Yz85ERmbdIGAgO9w":{"value":0},"-Kj8Yz_tVYvCM-ENoyua":{"value":0}}


.json is not work in the p.addParameter()?

DarkSabre

What happens when you SSH into the Yun and run that
Code: [Select]
curl https://[my project name].firebaseio.com/temperature.json
 from the command line?

nnitgd

When I try to this
Code: [Select]

curl https://mechanismboard.firebaseio.com/temperature.json


I get
Code: [Select]

curl performs SSL certificate verification by default, using a "bundle"
 of Certificate Authority (CA) public keys (CA certs). If the default
 bundle file isn't adequate, you can specify an alternate file
 using the --cacert option.
If this HTTPS server uses a certificate signed by a CA represented in
 the bundle, the certificate verification probably failed due to a
 problem with the certificate (it might be expired, or the name might
 not match the domain name in the URL).
If you'd like to turn off curl's verification of the certificate, use
 the -k (or --insecure) option.


So, I ran that
Code: [Select]

curl -k https://mechanismboard.firebaseio.com/temperature.json


I got the json value successfully
Code: [Select]

{"-Kj8Yz85ERmbdIGAgO9w":{"value":0},"-Kj8Yz_tVYvCM-ENoyua":{"value":0},"sdfe":{"wef":"wef"}}




nnitgd

Ohhhhh I success.
I ran that

Code: [Select]

#include <Process.h>

void setup() {
  // Initialize Bridge
  Bridge.begin();

  // Initialize Serial
  SerialUSB.begin(9600);

  // Wait until a Serial Monitor is connected.
  while (!SerialUSB);

  // run various example processes
  runCurl();
}

void loop() {
  // Do nothing here.
}

void runCurl() {
  // Launch "curl" command and get Arduino ascii art logo from the network
  // curl is command line program for transferring data using different internet protocols
  Process p;        // Create a process and call it "p"
  p.begin("curl");  // Process that launch the "curl" command
  p.addParameter("-k");
  p.addParameter("https://mechanismboard.firebaseio.com/temperature.json");
  p.run();      // Run the process and wait for its termination

  // Print arduino logo over the Serial
  // A process output can be read with the stream methods
  while (p.available()>0) {
    char c = p.read();
    SerialUSB.print(c);
  }
  // Ensure the last bit of data is sent.
  SerialUSB.flush();
}


Thank you

Go Up