Hello all,
i’m getting issue regarding device reconnect to thinger platform.
Here’s the details :
- Module NodeMCU v2
- Digital input for 2 sensors : motion sensor and reed switch (Connected to D3 & D6 pin)
- Using 5VDC power supply for NodeMCU
- Using our own thingerio VPS
- Wifi modem is stable
Everything is looks OK when device is connected to internet and the dashboard function of thingerio works fine. When electricity is going Off and become ON again, the device is ON but cannot connected to the internet and thinger server. But when i dismantle/unwire both sensor for D3 & D6 pin and tried to restart the device (unplug and plug again the 5V adaptor), it can connected to the thinger server automatically.
This is sneak peek of the code :
ThingerESP8266 thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);
void setup() {
Serial.begin(115200);
Serial.println();
//Set output mode for all IO pins
pinMode(output1, OUTPUT);
pinMode(output2, OUTPUT);
pinMode(reedSwitch, INPUT_PULLUP);
pinMode(switch1, INPUT);
pinMode(switch2, INPUT);
pinMode(detectPin, INPUT);
delay(10);
thing.add_wifi(SSID, SSID_PASSWORD);Serial.print(“connecting”);
thing[“sakelar1”]<< digitalPin(5);
thing[“sakelar2”]<< digitalPin(15);
thing[“suhu”] >> outputValue(dht.readTemperature());
thing[“kelembaban”] >> outputValue(dht.readHumidity());
// define the resource with temperature and humidity
thing[“data_suhu”] >> (pson& out){
out[“suhu”] = dht.readTemperature();
};
thing[“data_kelembaban”] >> (pson& out){
out[“kelembaban”] = dht.readHumidity();
};
thing[“doorStatus”] >> (pson& out){
out=doorState==0 ? “Tertutup”:“Terbuka”;
};thing[“motionDetection”]>>(pson& out){
out=motionState==0? “Gerakan terdeteksi!”:“Aman”;
};
mail.begin();
};void loop() {
doorDetection();
motionDetection();val = digitalRead(switch1);
if (val == HIGH && pusherIn)
{
digitalRead(15) ? digitalWrite(15, LOW) : digitalWrite(15, HIGH);
pusherIn=0; // need to declare this boolean variable to ensure the routine runs once
}
else if (val==LOW && !pusherIn)
{
pusherIn=1; // ready for next push
}val2 = digitalRead(switch2);
if (val2 == HIGH && pusherIn)
{
digitalRead(5) ? digitalWrite(5, LOW) : digitalWrite(5, HIGH);
pusherIn=0; // need to declare this boolean variable to ensure the routine runs once
}
else if (val2==LOW && !pusherIn)
{
pusherIn=1; // ready for next push
}thing.handle();
}void doorDetection() {
doorState = digitalRead(reedSwitch);
//door is going to close
if(doorState==1){
doorState = 0;
thing.stream(“doorStatus”);
delay(500);
}//door is going to open
else {
if(doorState==0){
doorState=1;
thing.stream(“doorStatus”);}
}
}void motionDetection()
{
motionState = digitalRead(detectPin);
if(motionState==0){
motionState = 1;
thing.stream(“motionDetection”);
delay(500);}
Does anybody experienced the same issue?
Any help is appreciated.
Cheers.