ESP8266 Presence Detection Notification To Mobile via IFTTT

Hi All; I’m building a tiny motion detection sensor using ESP8266-01 and PIR. Please refer to the code below. I registered the device o thinger.io and I added an Endpoint for the event and then trigger an IFTT event etc …all works like charm. The issue is after sometime (random) the device goes offline (thinger.io) and doesnt come back online till I reset it. Note, sometimes work for 30-40minutes others of 8-15min.

I doubt that there is hardware issue; I’m using one of the FT232RL to power the ESP8266 and the sensor. It provides regulated 3.3V and 5V.

I did think about te debug mode and collected some dump - attached to this email.

I’m not experienced with the ESP8266 and Thinger - I hope someone smarter than me can give me some advice.

Code:

#define _DEBUG_
#include <ESP8266WiFi.h>
#include <ThingerWifi.h> 
//#include <ThingerSmartConfig.h>

#define USERNAME "someuser"
#define DEVICE_ID "A001"
#define DEVICE_CREDENTIAL "some_credential"

#define SSID "SomeSSID"
#define SSID_PASSWORD "Some_Password"
int MOTION_SENSOR = 2;

ThingerWifi thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);
//ThingerSmartConfig thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);

void pinChanged() {
  thing.call_endpoint("MOTION_SENSOR");
  }
  
void setup() {
  Serial.begin(115200);
  delay(200);
  attachInterrupt(MOTION_SENSOR, pinChanged, RISING);
  thing.add_wifi(SSID, SSID_PASSWORD);

}

void loop() {
  thing.handle();
}

Some of the debug messages:
[NETWORK] Connecting to network HotSpot
[NETWORK] Connected to WiFi!
[NETWORK] Getting IP Address…
[NETWORK] Got IP Address: HotSpot
[NETWORK] Connected!
[_SOCKET] Connecting to iot.thinger.io:25200
[_SOCKET] Error while connecting!
[_SOCKET] Connecting to iot.thinger.io:25200
[_SOCKET] Connected!
[THINGER] Authenticating. User: SomeUser Device: A001
[THINGER] Writing bytes: 36 [OK]
[THINGER] Authenticated
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 2 [OK]
[THINGER] Available bytes: 2
[THINGER] Writing bytes: 2 [OK]
[THINGER] Available bytes: 2
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 2 [OK]
[THINGER] Available bytes: 2
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 2 [OK]
[THINGER] Available bytes: 2
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 2 [OK]
[THINGER] Available bytes: 2
[THINGER] Writing bytes: 2 [OK]
[THINGER] Available bytes: 2
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 2 [OK]
[THINGER] Available bytes: 2
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 2 [OK]
[THINGER] Available bytes: 2
[THINGER] Writing bytes: 2 [OK]
[THINGER] Available bytes: 2
[THINGER] Writing bytes: 2 [OK]
[THINGER] Available bytes: 2
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 2 [OK]
[THINGER] Available bytes: 2
[THINGER] Writing bytes: 2 [OK]
[THINGER] Available bytes: 2
[THINGER] Writing bytes: 22 [FAIL]
[_SOCKET] Connecting to iot.thinger.io:25200
[_SOCKET] Connected!
[THINGER] Authenticating. User: SomeUser Device: A001
[THINGER] Writing bytes: 36 [OK]
[THINGER] Authenticated
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 2 [OK]
[THINGER] Available bytes: 2
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 2 [OK]
[THINGER] Available bytes: 2
[THINGER] Writing bytes: 2 [OK]
[THINGER] Available bytes: 2
[THINGER] Writing bytes: 2 [OK]
[THINGER] Available bytes: 2
[THINGER] Writing bytes: 2 [OK]
[THINGER] Available bytes: 2
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 2 [FAIL]
[THINGER] Available bytes: 2
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 2 [OK]
[THINGER] Available bytes: 2
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 2 [OK]
[THINGER] Available bytes: 2
[THINGER] Writing bytes: 2 [OK]
[THINGER] Available bytes: 2
[THINGER] Writing bytes: 2 [OK]
[THINGER] Available bytes: 2
[THINGER] Writing bytes: 2 [OK]
[THINGER] Available bytes: 2
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 2 [OK]
[THINGER] Available bytes: 2
[THINGER] Writing bytes: 2 [OK]
[THINGER] Available bytes: 2
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 2 [OK]
[THINGER] Available bytes: 2
[THINGER] Writing bytes: 2 [OK]
[THINGER] Available bytes: 2
[THINGER] Writing bytes: 2 [OK]
[THINGER] Available bytes: 2
[THINGER] Writing bytes: 2 [OK]
[THINGER] Available bytes: 2
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 22 [FAIL]

[_SOCKET] Connecting to iot.thinger.io:25200
[_SOCKET] Connected!
[THINGER] Authenticating. User: SomeUserDevice: A001
[THINGER] Writing bytes: 36 [OK]
[THINGER] Authenticated
[THINGER] Writing bytes: 22 [FAIL]
[THINGER] Writing bytes: 2[THINGER] Writing bytes: 24
Exception (9):
epc1=0x401010e6 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000003 depc=0x00000000

ctx: sys
sp: 3ffffbf0 end: 3fffffb0 offset: 01a0

stack>>>
3ffffd90: 3fff11b0 00000018 00000002 3fff1188
3ffffda0: 00000018 4010124f 00000000 3fff1910
3ffffdb0: 00000001 00000000 402012d0 00001388
3ffffdc0: 3ffeec38 3ffeeb5c 3fff1128 00000000
3ffffdd0: 00000000 00000018 3fff0e70 40203eee
3ffffde0: 00000001 3ffeecfc 3ffeeb58 40203f18
3ffffdf0: 00000001 3ffeecfc 3ffeeb58 402021d9
3ffffe00: 00000008 3ffffe50 3ffeeb5c 3ffffe50
3ffffe10: 3ffeeb5c 3ffeeb58 00000000 40202bf4
3ffffe20: 3ffe8608 00000014 3fff1128 4020351c
3ffffe30: 3ffedf38 00000002 00000000 00000001
3ffffe40: c0035025 00000002 00000000 40203567
3ffffe50: 40220000 00000008 3fff10f8 00000000
3ffffe60: 736c6500 34617274 44444530 00000035
3ffffe70: 4010673c 00000000 00000000 4010678a
3ffffe80: ffffffff 00000020 00000000 3ffe9b08
3ffffe90: 00000000 00000000 0000001f 00000022
3ffffea0: 3fffc200 40106704 3fffc258 4000050c
3ffffeb0: 40000f68 00000030 00000011 ffffffff
3ffffec0: 40000f58 00000000 00000020 00000000
3ffffed0: 39143d29 00000001 00000000 bfffffff
3ffffee0: ffffffff 3fffc6fc fc70ffff 3fffdab0
3ffffef0: 00000000 3fffdcb0 3ffe8a60 00000030
3fffff00: 00000000 00000000 3ffebaef 3ffebb74
3fffff10: 3ffebb0c 3ffebb28 00000000 00000000
3fffff20: 3ffe90e4 4010124f 0000007d 4020b350
3fffff30: 00000001 00000000 40214a1b 3ffe90e4
3fffff40: 3ffe8a50 3ffe90e4 000175b1 4020b44c
3fffff50: 40214a84 3ffe90e4 3ffe8a50 b6a797fd
3fffff60: 00000001 00000000 40212998 60000600
3fffff70: 4020ec7c 3ffe8a50 3ffe8dec 4020ec5d
3fffff80: 4020eca2 3fffdab0 00000000 3fffdcb0
3fffff90: 3ffe8a60 40000f65 3fffdab0 00000000
3fffffa0: 40000f49 40000f49 3fffdab0 40000f49
<<<stack<<<

Exception (9):
epc1=0x40101155 epc2=0x00000000 epc3=0x00000000 excvaddr=0xffffffff depc=0x00000000

ctx: sys
sp: 3ffff9f0 end: 3fffffb0 offset: 01a0

stack>>>
3ffffb90: 00000001 00000000 00000014 40213d8f
3ffffba0: 4020ee06 3ffe8aa0 00000000 00000000
3ffffbb0: 00000004 4020efb7 3ffffd90 402011fa
3ffffbc0: 3ffffd90 0000000c a0120472 14bc877c
3ffffbd0: 40201348 3ffffd90 3fffffb0 4020120f
3ffffbe0: 3ffffd90 fffffff7 eb9002eb 4020120c
3ffffbf0: 00000020 00000008 00000038 3ffffcd0
3ffffc00: 00000002 00000009 401010e6 00000000
3ffffc10: 00000000 00000003 00000000 00000003
3ffffc20: 0000003c 3ffec970 3fff0690 3fff12d8
3ffffc30: 4022eff0 401010e6 00000000 00000000
3ffffc40: 00000000 00000003 00000000 40211bdd
3ffffc50: 00000002 00000009 401010e6 00000000
3ffffc60: 00000000 00000003 00000000 40101bb3
3ffffc70: 40101b94 3fffc100 00000000 00000009
3ffffc80: 00000009 401010e6 3ffe8eb8 3ffe8e40
3ffffc90: 400005e1 3ffe8eb8 3ffec970 7fffffff
3ffffca0: 401010e6 00000033 0000000b 4020db5d
3ffffcb0: ffffffff 392c29cf 3ffeec38 392c29cf
3ffffcc0: 3ffeec38 3ffe8a50 00010000 00a20000
3ffffcd0: 00000000 0000059c 00000018 0017d784
3ffffce0: 3ffeec38 00000000 00000000 00000009
3ffffcf0: 4010687e 3ffeeb58 00000001 3ffffd40
3ffffd00: 401013e5 3fff1168 3fff1168 4020218c
3ffffd10: 4010687e 3ffeeb58 00000001 00000000
3ffffd20: 401013e5 3fff1168 3fff1168 0000000d
3ffffd30: 3ffeecfc 00000001 3ffffd9f 40204fac
3ffffd40: 3ffeeb0d 00000001 3ffeeb5c 3ffeecfc
3ffffd50: 3fff11a0 4020a30b 00000000 3fff0db0
3ffffd60: 3fff0db0 00000000 3fff1910 00000000
3ffffd70: 00000000 0000000d 3ffffd9d 00000000
3ffffd80: 00000000 3fff0db0 00000000 4020a698
3ffffd90: 3fff11b0 00000018 00000002 3fff1188
3ffffda0: 00000018 4010124f 00000000 3fff1910
3ffffdb0: 00000001 00000000 402012d0 00001388
3ffffdc0: 3ffeec38 3ffeeb5c 3fff1128 00000000
3ffffdd0: 00000000 00000018 3fff0e70 40203eee
3ffffde0: 00000001 3ffeecfc 3ffeeb58 40203f18
3ffffdf0: 00000001 3ffeecfc 3ffeeb58 402021d9
3ffffe00: 00000008 3ffffe50 3ffeeb5c 3ffffe50
3ffffe10: 3ffeeb5c 3ffeeb58 00000000 40202bf4
3ffffe20: 3ffe8608 00000014 3fff1128 4020351c
3ffffe30: 3ffedf38 00000002 00000000 00000001
3ffffe40: c0035025 00000002 00000000 40203567
3ffffe50: 40220000 00000008 3fff10f8 00000000
3ffffe60: 736c6500 34617274 44444530 00000035
3ffffe70: 4010673c 00000000 00000000 4010678a
3ffffe80: ffffffff 00000020 00000000 3ffe9b08
3ffffe90: 00000000 00000000 0000001f 00000022
3ffffea0: 3fffc200 40106704 3fffc258 4000050c
3ffffeb0: 40000f68 00000030 00000011 ffffffff
3ffffec0: 40000f58 00000000 00000020 00000000
3ffffed0: 39143d29 00000001 00000000 bfffffff
3ffffee0: ffffffff 3fffc6fc fc70ffff 3fffdab0
3ffffef0: 00000000 3fffdcb0 3ffe8a60 00000030
3fffff00: 00000000 00000000 3ffebaef 3ffebb74
3fffff10: 3ffebb0c 3ffebb28 00000000 00000000
3fffff20: 3ffe90e4 4010124f 0000007d 4020b350
3fffff30: 00000001 00000000 40214a1b 3ffe90e4
3fffff40: 3ffe8a50 3ffe90e4 000175b1 4020b44c
3fffff50: 40214a84 3ffe90e4 3ffe8a50 b6a797fd
3fffff60: 00000001 00000000 40212998 60000600
3fffff70: 4020ec7c 3ffe8a50 3ffe8dec 4020ec5d
3fffff80: 4020eca2 3fffdab0 00000000 3fffdcb0
3fffff90: 3ffe8a60 40000f65 3fffdab0 00000000
3fffffa0: 40000f49 40000f49 3fffdab0 40000f49
<<<stack<<<

Exception (9):
epc1=0x40101155 epc2=0x00000000 epc3=0x00000000 excvaddr=0xffffffff depc=0x00000000

ctx: sys
sp: 3ffff7f0 end: 3fffffb0 offset: 01a0

stack>>>
3ffff990: 00000000 00000000 00000000 3ffff920
3ffff9a0: 4020ee06 3ffe8aa0 00000007 40008320
3ffff9b0: 00000004 4020efb7 3ffffb90 402011fa
3ffff9c0: 3ffffb90 0000000c 4021e78e ffffffff
3ffff9d0: 40201348 3ffffb90 3fffffb0 4020120f
3ffff9e0: 3ffffb90 fffffff7 00000010 4020120c
3ffff9f0: 00000020 00000000 00000010 00000000
3ffffa00: 00000002 00000009 40101155 00000000
3ffffa10: 00000000 ffffffff 00000000 ffffffff
3ffffa20: 0000003c 3ffedb50 00002000 00008000
3ffffa30: 4022eff0 40101155 00000000 00000000
3ffffa40: 00000000 ffffffff 00000000 40211bdd
3ffffa50: 00000002 00000009 40101155 00000000
3ffffa60: 00000000 ffffffff 00000000 40101bb3
3ffffa70: 40101b94 3fffc100 3fffffb0 00000009
3ffffa80: 00000009 40101155 0000001f 401011a1
3ffffa90: 400005e1 00000000 00000000 00000000
3ffffaa0: 40101155 00000033 00000005 ffffffe0
3ffffab0: ffffffff ffffffff 3fffdcc0 40080000
3ffffac0: 3ffe8a50 40000000 3fffdb00 3ffe9090
3ffffad0: 00000001 00000000 00000001 3ffe8aa4
3ffffae0: 3fffffb0 3fffffb0 00000020 00000009
3ffffaf0: 3fffd848 40002364 00000026 ffffffff
3ffffb00: 40001da0 00000078 00000000 00000010
3ffffb10: 40001f46 0000000b 915efb33 98d72355
3ffffb20: 30303034 39346630 4d130500 2f51a877
3ffffb30: d5ead8e9 83d0cf40 82541c72 f296b91f
3ffffb40: 4000b570 00000008 00000038 3ffffc20
3ffffb50: 00000000 00000000 00000000 00000000
3ffffb60: 00000000 3ffffbd0 3ffffbd0 3ffe87a0
3ffffb70: 40002514 3fffdd3c 3fffffb0 3fffffb0
3ffffb80: 00000020 00000008 00000004 00000000
3ffffb90: 00000001 00000000 00000014 40213d8f
3ffffba0: 4020ee06 3ffe8aa0 00000000 00000000
3ffffbb0: 00000004 4020efb7 3ffffd90 402011fa
3ffffbc0: 3ffffd90 0000000c a0120472 14bc877c
3ffffbd0: 40201348 3ffffd90 3fffffb0 4020120f
3ffffbe0: 3ffffd90 fffffff7 eb9002eb 4020120c
3ffffbf0: 00000020 00000008 00000038 3ffffcd0
3ffffc00: 00000002 00000009 401010e6 00000000
3ffffc10: 00000000 00000003 00000000 00000003
3ffffc20: 0000003c 3ffec970 3fff0690 3fff12d8
3ffffc30: 4022eff0 401010e6 00000000 00000000
3ffffc40: 00000000 00000003 00000000 40211bdd
3ffffc50: 00000002 00000009 401010e6 00000000
3ffffc60: 00000000 00000003 00000000 40101bb3
3ffffc70: 40101b94 3fffc100 00000000 00000009
3ffffc80: 00000009 401010e6 3ffe8eb8 3ffe8e40
3ffffc90: 400005e1 3ffe8eb8 3ffec970 7fffffff
3ffffca0: 401010e6 00000033 0000000b 4020db5d
3ffffcb0: ffffffff 392c29cf 3ffeec38 392c29cf
3ffffcc0: 3ffeec38 3ffe8a50 00010000 00a20000
3ffffcd0: 00000000 0000059c 00000018 0017d784
3ffffce0: 3ffeec38 00000000 00000000 00000009
3ffffcf0: 4010687e 3ffeeb58 00000001 3ffffd40
3ffffd00: 401013e5 3fff1168 3fff1168 4020218c
3ffffd10: 4010687e 3ffeeb58 00000001 00000000
3ffffd20: 401013e5 3fff1168 3fff1168 0000000d
3ffffd30: 3ffeecfc 00000001 3ffffd9f 40204fac
3ffffd40: 3ffeeb0d 00000001 3ffeeb5c 3ffeecfc
3ffffd50: 3fff11a0 4020a30b 00000000 3fff0db0
3ffffd60: 3fff0db0 00000000 3fff1910 00000000
3ffffd70: 00000000 0000000d 3ffffd9d 00000000
3ffffd80: 00000000 3fff0db0 00000000 4020a698
3ffffd90: 3fff11b0 00000018 00000002 3fff1188
3ffffda0: 00000018 4010124f 00000000 3fff1910
3ffffdb0: 00000001 00000000 402012d0 00001388
3ffffdc0: 3ffeec38 3ffeeb5c 3fff1128 00000000
3ffffdd0: 00000000 00000018 3fff0e70 40203eee
3ffffde0: 00000001 3ffeecfc 3ffeeb58 40203f18
3ffffdf0: 00000001 3ffeecfc 3ffeeb58 402021d9
3ffffe00: 00000008 3ffffe50 3ffeeb5c 3ffffe50
3ffffe10: 3ffeeb5c 3ffeeb58 00000000 40202bf4
3ffffe20: 3ffe8608 00000014 3fff1128 4020351c
3ffffe30: 3ffedf38 00000002 00000000 00000001
3ffffe40: c0035025 00000002 00000000 40203567
3ffffe50: 40220000 00000008 3fff10f8 00000000
3ffffe60: 736c6500 34617274 44444530 00000035
3ffffe70: 4010673c 00000000 00000000 4010678a
3ffffe80: ffffffff 00000020 00000000 3ffe9b08
3ffffe90: 00000000 00000000 0000001f 00000022
3ffffea0: 3fffc200 40106704 3fffc258 4000050c
3ffffeb0: 40000f68 00000030 00000011 ffffffff
3ffffec0: 40000f58 00000000 00000020 00000000
3ffffed0: 39143d29 00000001 00000000 bfffffff
3ffffee0: ffffffff 3fffc6fc fc70ffff 3fffdab0
3ffffef0: 00000000 3fffdcb0 3ffe8a60 00000030
3fffff00: 00000000 00000000 3ffebaef 3ffebb74
3fffff10: 3ffebb0c 3ffebb28 00000000 00000000
3fffff20: 3ffe90e4 4010124f 0000007d 4020b350
3fffff30: 00000001 00000000 40214a1b 3ffe90e4
3fffff40: 3ffe8a50 3ffe90e4 000175b1 4020b44c
3fffff50: 40214a84 3ffe90e4 3ffe8a50 b6a797fd
3fffff60: 00000001 00000000 40212998 60000600
3fffff70: 4020ec7c 3ffe8a50 3ffe8dec 4020ec5d
3fffff80: 4020eca2 3fffdab0 00000000 3fffdcb0
3fffff90: 3ffe8a60 40000f65 3fffdab0 00000000
3fffffa0: 40000f49 40000f49 3fffdab0 40000f49
<<<stack<<<

Exception (9):
epc1=0x40101155 epc2=0x00000000 epc3=0x00000000 excvaddr=0xffffffff depc=0x00000000

It should be a hardware issue. I think it is not safe to power ESP8266 from FT232RL as it won’t be able to provide enough current during some TX/RX operations, as the 3.3v output is not intended for power supply (it can provide 50mA at most, and the ESP8266 can consume up to 170mA + PIR sensor consumption). So I recommend you to test your setup using a external power supply to avoid burn your FT232RL. This is causing a random behaviour depending on TX/RX consumption, as it is not always the same, depending on the network, signal, etc.

From FT232RL datasheet:

3.3V output from integrated L.D.O. regulator. This pin should be decoupled to ground using a 100nF capacitor. The prime purpose of this pin is to provide the internal 3.3V supply to the USB transceiver cell and the internal 1.5k[ch937] pull up resistor on USBDP. Up to 50mA can be drawn from this pin to power external logic if required. This pin can also be used to supply the FT232R’s VCCIO pin.

After reading the code deeper, I also recommend you to avoid calling the call_endpoint method directly in the interrupt. As interrupts may execute so fast, but call_endpoint is not a cheap operation for a microcontroller. It also may provoke writing to the socket even before the device has logged in or connected, that will provoke unexpected behaviour. I recommend you to update your code to the following one:

#define _DEBUG_
#include <ESP8266WiFi.h>
#include <ThingerWifi.h> 
//#include <ThingerSmartConfig.h>

#define USERNAME "someuser"
#define DEVICE_ID "A001"
#define DEVICE_CREDENTIAL "some_credential"

#define SSID "SomeSSID"
#define SSID_PASSWORD "Some_Password"
int MOTION_SENSOR = 2;

ThingerWifi thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);
//ThingerSmartConfig thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);

bool motion_detected = false;
void pinChanged() {
  motion_detected = true;
}
  
void setup() {
  Serial.begin(115200);
  delay(200);
  attachInterrupt(MOTION_SENSOR, pinChanged, RISING);
  thing.add_wifi(SSID, SSID_PASSWORD);

}
void loop() {
  thing.handle();
  if(motion_detected){
    thing.call_endpoint("MOTION_SENSOR");
    motion_detected = false;
  }
}

Other alternative is to read the pin state in the loop, and avoid using the interrupt.

Maybe it solves your problem with the unestability, but anyways, I recommend you to use a external powe supply for this.

Noted well. Thanks for the advice. I will attempt an independent power source with >350mA and regulated 3.3V and post back the results.

I agree that sounds smarter as interrupt will take the processor to a new state where all other operates are suspended. Possibly causing the wifi or thing handle to time-out ?

Will re-program the ESP8266 and post the results back.

Kind of you to share your thoughts - thanks for the feedback.

Many Thanks Alvarolb; it seems you got it spot on. It was the interrupt routine taking too long causing this issue. I used your code as is.

Tested it for 2 hours with motion activities every 8 seconds.

Many thanks for the advice.

My debug output is now more like this:

[THINGER] Writing bytes: 22 [OK]
[THINGER] Writing bytes: 22 [OK]
[THINGER] Writing bytes: 2 [OK]
[THINGER] Available bytes: 2
[THINGER] Writing bytes: 2 [OK]
[THINGER] Available bytes: 2
[THINGER] Writing bytes: 2 [OK]
[THINGER] Available bytes: 2
[THINGER] Writing bytes: 2 [OK]
[THINGER] Available bytes: 2
[THINGER] Writing bytes: 2 [OK]
[THINGER] Available bytes: 2
[THINGER] Writing bytes: 2 [OK]
[THINGER] Available bytes: 2
[THINGER] Writing bytes: 22 [OK]
[THINGER] Writing bytes: 22 [OK]

Great! Glad it worked… :slightly_smiling:

Just one question, what kind of IFTTT events are your calling? Reporting a motion activity every 8 seconds seems quite a lot!

Sorry I was not very clear. My PIR reports 3.3v on motion detection and it stays “ON” for 8 seconds. So can not detect multple motions within 8 seconds frame. It stays “ON” as long as the motion is being detected. Which is why I’m using the RISING edge only. Seems to do the job for me.

Upon motion detection the Thing handler is calling the EndPoint which in turn is communicating with IFTT event. On my iPhone I set the IFFT to send push notification upon Maker event.
For IFTT maker you need to make sure the event name is consistent with Endpoint and the ESP8266 code.

The funny part that it costs me $77AUD to buy a DLink motion detector; now it costs me $5AUD only.
I attached the Thinger config for reference.

1 Like

It is much more clear now! It makes sense now. Thanks for sharing your configuration :wink:

In the future, it will be possible to send mobile notifications right from the thinger platform, without having to configure IFTTT channels, but in the meantime this is the perfect solution!

Keep us updated about the stability of your setup!

Thanks for the help. I just added an option to activate/de-activate notifications via Thinger. Also can be controlled with “DO Button” from IFTT.

Also working charm. Maybe I should stop making more comments in this thread.

int MOTION_SENSOR = 2;
bool NOTIFICATION = HIGH; // "HIGH" the handle will call endpoint and hence notify user. In the future initialize from cloud
bool MOTION_DETECTED = false;

ThingerWifi thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);
//ThingerSmartConfig thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);

void pinChanged() {
  MOTION_DETECTED = true;
}
  
void setup() {
  Serial.begin(115200);
  delay(200);
  attachInterrupt(MOTION_SENSOR, pinChanged, RISING);
  thing.add_wifi(SSID, SSID_PASSWORD);
  thing["notif"] << [](pson& in){
    NOTIFICATION = in;
    };
}
void loop() {
  thing.handle();
  if(MOTION_DETECTED & NOTIFICATION){
    thing.call_endpoint("MOTION_SENSOR");
    MOTION_DETECTED = false;
  }
}
2 Likes

I would improve your sketch by changing the resource notif as the following:

thing["notif"] << inputValue(NOTIFICATION,{
     /* here you could even attach/detach the interruption based on the updated NOTIFICATION
        value, turn off the PIR sensor, etc., but it is not really necessary */
});

This way, when you access your device from the API Explorer, from the Android APP, or from a control widget in the dashboard, you can see the current state of the NOTIFICATION (not always off) value, so you can turn it on and off more easily. Did you tried any of this variants to handle the notification state?

Maybe we can change the topic name to something more representative, as the conversation is evolving, what do you think about “ESP8266 Presence Detection Notification To Mobile via IFTTT”?

Taken. Thanks for the advice. Is there is a way to read the NOTIFICATION value from Thinger at boot?
In my code I initialized it to HIGH. But I would like the device to remember the last state and I guess that shouldn’t be maintained in the EPROM.

What do you think?

This is a planned feature for thinger.io! At this moment there is no other alternative than using the EEPROM/FLASH, which is so easy to manage. In this case you can use the notif resource to update the EPROOM value.