Problem on passing the sensor data to dashboard


#1

hi guys… i got a bit of problem when passing the temperature value from lm35 to thinger.io dashboard. it should be temperature value on my dashboard. here i attach my code.

ThingerESP8266 thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);

int input;

float tempPin = A0;
float tempValue;
float tValue;

int lampStatus;
int motoStatus;

int relayLamp=16;
int relayMoto=5;

char notifyH[]=“1”;
char notifyL[]=“2”;
char notifyM[]=“3”;

void setup() {
Serial.begin(9600);

WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print(“connecting”);
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(500);
}
Serial.println();
Serial.print("connected: ");
Serial.println(WiFi.localIP());
Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
pinMode(relayLamp,OUTPUT);
pinMode(relayMoto,OUTPUT);

thing.add_wifi(WIFI_SSID,WIFI_PASSWORD);
thing[“Motor”] << digitalPin(relayMoto);
thing[“Lamp”] << digitalPin(relayLamp);
//thing[“Temperature”] >> [](pson& out){
//out[“Temp”] = analogRead(tempPin = A0);};
thing[“Temperature”] >> [](pson & out){
out = (unsigned int) analogRead(A0);
};

}

void loop()
{
thing.handle();
TempValue();
operation();
//test();
controlLamp();
controlMotor();

}

/*void test() //status
{
if(Serial.available()) // do nothing if nothing sent
input = Serial.read();
{
if(input == ‘1’)
{
Firebase.setString (“Status”,notifyH);
Serial.println(“1”);
//digitalWrite(relayLamp,HIGH);
//digitalWrite(relayMoto,HIGH);
}
if(input == ‘2’)
{
Firebase.setString (“Status”,notifyL);
Serial.println(“2”);
//digitalWrite(relayLamp,HIGH);
//digitalWrite(relayMoto,HIGH);
}

if(input == ‘3’)
{
Firebase.setString (“Status”,notifyM);
Serial.println(“3”);
// digitalWrite(relayMoto,LOW);
// digitalWrite(relayLamp,LOW) ;
}
}

}*/

void TempValue()
{
tempValue= analogRead(tempPin);
tempValue = ( tempValue/1024.0)*3300/10;

Serial.println(tempValue);
Firebase.setFloat (“Temp”, tempValue);
delay(1000);

}

void operation() //relay
{
delay(1000);
if (tempValue < 21) //when temp is below 21 degrees
{
digitalWrite(relayMoto, LOW); //water pump off
digitalWrite(relayLamp, HIGH); //led lamp on
Firebase.setString (“Status”,notifyL);
}
else if (tempValue > 29) //when temp is above 29 degrees
{
digitalWrite(relayMoto, HIGH); //water pump on
digitalWrite(relayLamp, LOW); //led lamp is off
Firebase.setString (“Status”,notifyH);
}
else //when between 21-29 degrees
{
digitalWrite(relayMoto, LOW); //water pumpis off
digitalWrite(relayLamp, LOW); //led lamp is off
Firebase.setString (“Status”,notifyM);
}
}

void controlLamp()
{
lampStatus = Firebase.getInt(“Lamp”);

if (lampStatus == 1)
{
//(“Lamp ON”);

}
else if(lampStatus == 2)
{
//(“Lamp OFF”);

}

}

void controlMotor()
{
motoStatus = Firebase.getInt(“Motor”);

if(motoStatus == 3)
{
//(“Motor Pump OFF”);

}
else if(motoStatus == 4)
{
//(“Motor Pump ON”);

}
}


#2

Please, can you format your code?, like:

```cpp
Your code Here
```