Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sending Data from a Structure to Firebase #553

Open
Anonymouse-X opened this issue Dec 7, 2022 · 1 comment
Open

Sending Data from a Structure to Firebase #553

Anonymouse-X opened this issue Dec 7, 2022 · 1 comment

Comments

@Anonymouse-X
Copy link

Anonymouse-X commented Dec 7, 2022

I have my sensor data in Structure sent via 433Mhz freq. and received in Arduino.

The data is structured this way;

`
struct Data {
byte a;
float b;
float c;
float d;
float e;
float f;
float g;
float h;
float i;
} data;

`

And I have this print in my Arduino

`
Serial.flush();
Serial.print("Node");
Serial.print(data.a, HEX); Serial.print(",");
Serial.print(data.b); Serial.print(",");
Serial.print(data.c); Serial.print(",");
Serial.print(data.d); Serial.print(",");
Serial.print(data.e); Serial.print(",");
Serial.print(data.f); Serial.print(",");
Serial.print(data.g); Serial.print(",");
Serial.print(data.h); Serial.print(",");
Serial.print(data.i); Serial.println("");

`

This is a sample output on the serial monitor

`

NodeDD,5.86,-20.28,-118.82,573.00,-21.43,-12280.19,109.37,1.00
NodeBB,10.43,-6.76,-70.46,1008.00,-7.09,-7145.77,202.15,1.00
NodeDD,5.76,-20.25,-116.62,551.00,-21.37,-11775.27,101.07,1.00
NodeBB,10.43,-6.75,-70.41,1008.00,-7.10,-7159.19,202.15,1.00
NodeDD,5.52,-20.09,-110.91,537.00,-21.27,-11424.43,102.05,1.00
NodeBB,10.41,-6.77,-70.49,1008.00,-7.13,-7186.04,201.66,1.00
NodeDD,5.79,-20.23,-117.15,566.00,-21.40,-12110.91,107.42,1.00
NodeBB,10.41,-6.80,-70.84,1008.00,-7.10,-7152.73,201.66,1.00

`

And have this code flashed in my esp-01 (this is the code inside the loop).

`

while(Serial.available()){

timeClient.update();
String epoch = String(timeClient.getEpochTime());
Serial.println(epoch);
char inChar = (char)Serial.read();

values += inChar;

if(inChar == '\n'){  

  //get comma indexes from values variable
  int node = values.indexOf(',');
  int batt_volt = values.indexOf(',', node + 1);
  int batt_curr = values.indexOf(',', batt_volt + 1);
  int batt_pow = values.indexOf(',', batt_curr + 1);
  int solar_volt = values.indexOf(',', batt_pow + 1);
  int solar_curr = values.indexOf(',', solar_volt + 1);
  int solar_pow = values.indexOf(',', solar_curr + 1);
  int temp = values.indexOf(',', solar_pow + 1);
  int lux = values.indexOf(',', temp + 1);
  int end = values.indexOf(',', lux + 1);
  
  //get sensors data from values variable by  spliting by commas and put in to variables
  String node_value = values.substring(0, node);  
  String batt_volt_value = values.substring(node + 1, batt_volt);
  String batt_curr_value = values.substring(batt_volt + 1, batt_curr);
  String batt_pow_value = values.substring(batt_curr + 1, batt_pow);
  String solar_volt_value = values.substring(batt_pow + 1, solar_volt);
  String solar_curr_value = values.substring(solar_volt + 1, solar_curr);
  String solar_pow_value = values.substring(solar_curr + 1, solar_pow);
  String temp_value = values.substring(solar_pow + 1, temp);
  String lux_value = values.substring(temp + 1, lux);

        
  Firebase.setString("monitoring/" + epoch + "/originNode" + node_value + "/batteryVoltage", batt_volt_value);

  Firebase.setString("monitoring/" + epoch + "/originNode" + node_value + "/batteryCurrent", batt_curr_value);

  Firebase.setString("monitoring/" + epoch + "/originNode" + node_value + "/batteryPower", batt_pow_value);

  Firebase.setString("monitoring/" + epoch + "/originNode" + node_value + "/solarpanelVoltage", solar_volt_value);

  Firebase.setString("monitoring/" + epoch + "/originNode" + node_value + "/solarpanelCurrent", solar_curr_value);

  Firebase.setString("monitoring/" + epoch + "/originNode" + node_value + "/solarpanelPower", solar_pow_value);

  Firebase.setString("monitoring/" + epoch + "/originNode" + node_value + "/temperature", temp_value);

  Firebase.setString("monitoring/" + epoch + "/originNode" + node_value + "/lux", lux_value);

values = "";  

  
}  

}

if (Firebase.failed()) {
return;

}

`

but nothing is showing in my database. What should I do?

Wifi is connected, I also check the Host and Auth.
@squashfold
Copy link

Have you tried logging out any errors?

Serial.println(FirebaseDataObject.errorReason()); (replace FirebaseDataObject with whatever you've called it)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants