I am a newbie to arduino and programming.
I need some help with my project. I am sending distance sensor data to a website called firebase (like thingspeak, https://firebase.google.com/) and I want to use this data to control a motor on another device. In both scenarios I am using a Wemos D1 mini ( microcontroller using Arduino IDE with ESP8266 Wifi chip). I have problems in receive the data from firebase.
Here is a helping manual that doesn't help me as a programming starter, maybe somebody can help me with this riddle? Recuperar dados | Firebase Realtime Database
Here is a part of my sending code:
void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
//Calculate the distance (in cm) based on the speed of sound.
float distance = float (duration/58.2);
Serial.println(distance);
Serial.print ( " cm");
StaticJsonBuffer<200> jsonBuffer;
JsonObject& data = jsonBuffer.createObject();
data["dis"] = distance;
StaticJsonBuffer<200> jsonBuffer;
JsonObject& data = jsonBuffer.createObject();
data["dis"] = distance;
String distance = Firebase.get("DISTANCE", data)
servoAngle = (106./7.) * distance + 37; //Calculate Servo Angle from targetDistance
//for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo.write(servoAngle); // write servoAngle to the servo __ tell servo to go to position in variable 'pos'
Serial.println(servoAngle);
delay(150); // waits 15ms for the servo to reach the position
return;
Okay, I was trying to say that I don't know how to implement the code for retreiving data.
the Firebase.get actually doesn't exist. I had this thing working on thingspeak and was hoping to get anywhere with it but I don't.
the help part in firebase shows me this example but I can't make it work with my sketch
this is the help code
public static class Post {
public String author;
public String title;
public Post(String author, String title) {
// ...
}
}
// Get a reference to our posts
final FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference ref = database.getReference("server/saving-data/fireblog/posts");
// Attach a listener to read the data at our posts reference
ref.addValueEventListener(new ValueEventListener() { @Override
public void onDataChange(DataSnapshot dataSnapshot) {
Post post = dataSnapshot.getValue(Post.class);
System.out.println(post);
}