0

GroupSensors not working with ESP8266 - WDT crash on second
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

GroupSensors not working with ESP8266 - WDT crash on second

by daemach on Thu Oct 29, 2015 12:16 pm

I'm trying to get started with the esp8266 Group Sensors example and I'm not having much luck at the moment.

After hacking this into my own code, it seems to work once, at least from the serial monitor, but then it does a WDT crash on the second connect attempt. See the debug output below. I have already regenerated my key ;)

It says success one time every time I run this. The second time it always crashes, reboots then does it all over again. Oddly, I only see 1 single update for my feeds in the io feed list - it happened an hour ago and most of the values seem to be 0, which is really strange given that it has been looping for quite a while.



=========================================
I live...
ST7735 TFT initialized!
Connecting to CalypsoAP
.................
WiFi connected
IP address:
192.168.1.154
Connecting to Adafruit IO... Connecting to: io.adafruit.com
Connect result: 1
MQTT connect packet:
[0x10], N [0x4E], [0x00], [0x04], M [0x4D], Q [0x51], T [0x54], T [0x54],
[0x04], Â [0xC2], [0x01], , [0x2C], [0x00], [0x0F], 0 [0x30], 8 [0x38],
: [0x3A], 5 [0x35], 6 [0x36], : [0x3A], 1 [0x31], 6 [0x36], d [0x64], a [0x61],
e [0x65], m [0x6D], a [0x61], c [0x63], h [0x68], [0x00], [0x07], d [0x64],
a [0x61], e [0x65], m [0x6D], a [0x61], c [0x63], h [0x68], [0x00], ( [0x28],
b [0x62], 0 [0x30], 5 [0x35], 6 [0x36], 1 [0x31], f [0x66], 1 [0x31], 7 [0x37],
5 [0x35], 6 [0x36], 9 [0x39], 8 [0x38], 8 [0x38], 1 [0x31], 2 [0x32], 7 [0x37],
5 [0x35], 1 [0x31], d [0x64], b [0x62], a [0x61], 6 [0x36], b [0x62], 5 [0x35],
d [0x64], 9 [0x39], d [0x64], 8 [0x38], 7 [0x37], e [0x65], b [0x62], 3 [0x33],
0 [0x30], 4 [0x34], 2 [0x32], b [0x62], 8 [0x38], 8 [0x38], 6 [0x36], a [0x61],

sendPacket returned: 80
Read packet: [0x20], [0x02], [0x00], [0x00],
Adafruit IO Connected!
I'm Idle
SHT20 here --> Humidity(%RH): 48.4 Temperature(C/F): 24.9/56.9
IAQ-Core here --> 450 16 119881 115325
MPL here --> Altitude(M/ft):89.56/293.84 Pressure(Pa):358.25 Temp(C):26.81 Altimeter setting InHg:0.10
I'm REFRESH
I'm Idle
SHT20 here --> Humidity(%RH): 48.5 Temperature(C/F): 24.9/56.9
IAQ-Core here --> 450 16 119881 115325
MPL here --> Altitude(M/ft):89.56/293.84 Pressure(Pa):100263.75 Temp(C):26.56 Altimeter setting InHg:30.09
I'm REFRESH
I'm Idle
SHT20 here --> Humidity(%RH): 48.6 Temperature(C/F): 24.8/56.8
IAQ-Core here --> 450 16 119881 115325
MPL here --> Altitude(M/ft):89.56/293.84 Pressure(Pa):100262.00 Temp(C):26.56 Altimeter setting InHg:30.09
I'm REFRESH
I'm Idle
SHT20 here --> Humidity(%RH): 48.8 Temperature(C/F): 24.8/56.8
IAQ-Core here --> 450 16 119881 115325
MPL here --> Altitude(M/ft):89.56/293.84 Pressure(Pa):100266.00 Temp(C):26.56 Altimeter setting InHg:30.10
I'm REFRESH
I'm Idle
SHT20 here --> Humidity(%RH): 49.0 Temperature(C/F): 24.8/56.8
IAQ-Core here --> 450 16 119881 115325
MPL here --> Altitude(M/ft):89.56/293.84 Pressure(Pa):100266.00 Temp(C):26.56 Altimeter setting InHg:30.10
I'm REFRESH
I'm Idle
SHT20 here --> Humidity(%RH): 49.0 Temperature(C/F): 24.7/56.7
IAQ-Core here --> 450 16 119881 115325
MPL here --> Altitude(M/ft):89.56/293.84 Pressure(Pa):100262.25 Temp(C):26.50 Altimeter setting InHg:30.09
I'm REFRESH
I'm Idle
SHT20 here --> Humidity(%RH): 49.0 Temperature(C/F): 24.7/56.7
IAQ-Core here --> 450 16 119881 115325
MPL here --> Altitude(M/ft):89.56/293.84 Pressure(Pa):100265.75 Temp(C):26.50 Altimeter setting InHg:30.10
I'm REFRESH
I'm Idle
SHT20 here --> Humidity(%RH): 49.0 Temperature(C/F): 24.7/56.7
IAQ-Core here --> 450 16 119881 115325
MPL here --> Altitude(M/ft):89.56/293.84 Pressure(Pa):100264.75 Temp(C):26.50 Altimeter setting InHg:30.10
I'm REFRESH
I'm Idle
SHT20 here --> Humidity(%RH): 49.0 Temperature(C/F): 24.6/56.6
IAQ-Core here --> 450 16 124096 115325
MPL here --> Altitude(M/ft):89.56/293.84 Pressure(Pa):100263.00 Temp(C):26.44 Altimeter setting InHg:30.09
I'm REFRESH
I'm Idle
SHT20 here --> Humidity(%RH): 49.2 Temperature(C/F): 24.6/56.6
IAQ-Core here --> 450 16 124096 115325
MPL here --> Altitude(M/ft):89.56/293.84 Pressure(Pa):100265.25 Temp(C):26.44 Altimeter setting InHg:30.10
I'm REFRESH
I'm Idle
Flushing input buffer
MQTT ping packet:
À [0xC0], [0x00],
sendPacket returned: 2
Read packet: Ð [0xD0], [0x00],

Sending:
Altitude,89.56
Temperature,24.58
Humidity,49.15
Temperature2,26.44
AirQuality,450.00
Pressure,30.10
MQTT publish packet:
0 [0x30], ‚ [0x82], [0x00], [0x1D], d [0x64], a [0x61], e [0x65], m [0x6D],
a [0x61], c [0x63], h [0x68], / [0x2F], g [0x67], r [0x72], o [0x6F], u [0x75],
p [0x70], s [0x73], / [0x2F], a [0x61], i [0x69], r [0x72], Q [0x51], u [0x75],
a [0x61], l [0x6C], i [0x69], t [0x74], y [0x79], / [0x2F], c [0x63], s [0x73],
v [0x76], A [0x41], l [0x6C], t [0x74], i [0x69], t [0x74], u [0x75], d [0x64],
e [0x65], , [0x2C], 8 [0x38], 9 [0x39], . [0x2E], 5 [0x35], 6 [0x36], [0x0A],
T [0x54], e [0x65], m [0x6D], p [0x70], e [0x65], r [0x72], a [0x61], t [0x74],
u [0x75], r [0x72], e [0x65], , [0x2C], 2 [0x32], 4 [0x34], . [0x2E], 5 [0x35],
8 [0x38], [0x0A], H [0x48], u [0x75], m [0x6D], i [0x69], d [0x64], i [0x69],
t [0x74], y [0x79], , [0x2C], 4 [0x34], 9 [0x39], . [0x2E], 1 [0x31], 5 [0x35],
[0x0A], T [0x54], e [0x65], m [0x6D], p [0x70], e [0x65], r [0x72], a [0x61],
t [0x74], u [0x75], r [0x72], e [0x65], 2 [0x32], , [0x2C], 2 [0x32], 6 [0x36],
. [0x2E], 4 [0x34], 4 [0x34], [0x0A], A [0x41], i [0x69], r [0x72], Q [0x51],
u [0x75], a [0x61], l [0x6C], i [0x69], t [0x74], y [0x79], , [0x2C], 4 [0x34],
5 [0x35], 0 [0x30], . [0x2E], 0 [0x30], 0 [0x30], [0x0A], P [0x50], r [0x72],
e [0x65], s [0x73], s [0x73], u [0x75], r [0x72], e [0x65], , [0x2C], 3 [0x33],
0 [0x30], . [0x2E], 1 [0x31], 0 [0x30],
sendPacket returned: 132
Success!
I'm Idle
SHT20 here --> Humidity(%RH): 49.3 Temperature(C/F): 24.5/56.5
IAQ-Core here --> 450 16 124096 115325
MPL here --> Altitude(M/ft):89.56/293.84 Pressure(Pa):100263.00 Temp(C):26.44 Altimeter setting InHg:30.09
I'm REFRESH
I'm Idle
SHT20 here --> Humidity(%RH): 49.3 Temperature(C/F): 24.5/56.5
IAQ-Core here --> 450 16 124096 115325
MPL here --> Altitude(M/ft):89.56/293.84 Pressure(Pa):100267.00 Temp(C):26.44 Altimeter setting InHg:30.10
I'm REFRESH
I'm Idle
SHT20 here --> Humidity(%RH): 49.4 Temperature(C/F): 24.5/56.5
IAQ-Core here --> 450 16 124096 115325
MPL here --> Altitude(M/ft):89.56/293.84 Pressure(Pa):100265.25 Temp(C):26.44 Altimeter setting InHg:30.10
I'm REFRESH
I'm Idle
SHT20 here --> Humidity(%RH): 49.4 Temperature(C/F): 24.4/56.4
IAQ-Core here --> 450 16 124096 115325
MPL here --> Altitude(M/ft):89.56/293.84 Pressure(Pa):100266.25 Temp(C):26.37 Altimeter setting InHg:30.10
I'm REFRESH
I'm Idle
SHT20 here --> Humidity(%RH): 49.5 Temperature(C/F): 24.4/56.4
IAQ-Core here --> 450 16 124096 115325
MPL here --> Altitude(M/ft):89.56/293.84 Pressure(Pa):100267.50 Temp(C):26.37 Altimeter setting InHg:30.10
I'm REFRESH
I'm Idle
SHT20 here --> Humidity(%RH): 49.5 Temperature(C/F): 24.4/56.4
IAQ-Core here --> 450 16 126813 115325
MPL here --> Altitude(M/ft):89.56/293.84 Pressure(Pa):100268.00 Temp(C):26.37 Altimeter setting InHg:30.10
I'm REFRESH
I'm Idle
SHT20 here --> Humidity(%RH): 49.6 Temperature(C/F): 24.3/56.3
IAQ-Core here --> 450 16 126813 115325
MPL here --> Altitude(M/ft):89.56/293.84 Pressure(Pa):100266.75 Temp(C):26.37 Altimeter setting InHg:30.10
I'm REFRESH
I'm Idle
SHT20 here --> Humidity(%RH): 49.7 Temperature(C/F): 24.3/56.3
IAQ-Core here --> 450 16 126813 115325
MPL here --> Altitude(M/ft):89.56/293.84 Pressure(Pa):100264.00 Temp(C):26.31 Altimeter setting InHg:30.09
I'm REFRESH
I'm Idle
SHT20 here --> Humidity(%RH): 49.7 Temperature(C/F): 24.3/56.3
IAQ-Core here --> 450 16 126813 115325
MPL here --> Altitude(M/ft):89.56/293.84 Pressure(Pa):100269.25 Temp(C):26.31 Altimeter setting InHg:30.10
I'm REFRESH
I'm Idle
SHT20 here --> Humidity(%RH): 49.8 Temperature(C/F): 24.2/56.2
IAQ-Core here --> 450 16 126813 115325
MPL here --> Altitude(M/ft):89.56/293.84 Pressure(Pa):100266.75 Temp(C):26.31 Altimeter setting InHg:30.10
I'm REFRESH
I'm Idle
Flushing input buffer
MQTT ping packet:
À [0xC0], [0x00],
Connection failed!
MQTT ping packet:
À [0xC0], [0x00],
Connection failed!
MQTT ping packet:
À [0xC0], [0x00],
Connection failed!
Connecting to Adafruit IO... Connecting to: io.adafruit.com
Connect result: 1
MQTT connect packet:
[0x10], N [0x4E], [0x00], [0x04], M [0x4D], Q [0x51], T [0x54], T [0x54],
[0x04], Â [0xC2], [0x01], , [0x2C], [0x00], [0x0F], 0 [0x30], 8 [0x38],
: [0x3A], 5 [0x35], 6 [0x36], : [0x3A], 1 [0x31], 6 [0x36], d [0x64], a [0x61],
e [0x65], m [0x6D], a [0x61], c [0x63], h [0x68], [0x00], [0x07], d [0x64],
a [0x61], e [0x65], m [0x6D], a [0x61], c [0x63], h [0x68], [0x00], ( [0x28],
b [0x62], 0 [0x30], 5 [0x35], 6 [0x36], 1 [0x31], f [0x66], 1 [0x31], 7 [0x37],
5 [0x35], 6 [0x36], 9 [0x39], 8 [0x38], 8 [0x38], 1 [0x31], 2 [0x32], 7 [0x37],
5 [0x35], 1 [0x31], d [0x64], b [0x62], a [0x61], 6 [0x36], b [0x62], 5 [0x35],
d [0x64], 9 [0x39], d [0x64], 8 [0x38], 7 [0x37], e [0x65], b [0x62], 3 [0x33],
0 [0x30], 4 [0x34], 2 [0x32], b [0x62], 8 [0x38], 8 [0x38], 6 [0x36], a [0x61],

sendPacket returned: 80
Read packet: [0x20], [0x02], [0x00], [0x00],

Exception (9):
epc1=0x402067a8 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00003031 depc=0x00000000

ctx: cont
sp: 3ffebce0 end: 3ffec010 offset: 01a0

>>>stack>>>
3ffebe80: 3ffec068 0000001c 4024cfd5 3ffec03c
3ffebe90: 3ffeab6c 3ffeab6c 3ffec068 40202728
3ffebea0: 402019da 00000064 00000064 3ffec03c
3ffebeb0: 3ffeab6c 3ffe8010 3ffec068 402030c9
3ffebec0: 69746c41 65647574 2e39382c 540a3635
3ffebed0: 65706d65 75746172 322c6572 38352e34
3ffebee0: 6d75480a 74696469 39342c79 0a35312e
3ffebef0: 706d6554 74617265 32657275 2e36322c
3ffebf00: 410a3434 75517269 74696c61 35342c79
3ffebf10: 30302e30 6572500a 72757373 30332c65
3ffebf20: 0030312e 00000000 3fff39c8 40204d39
3ffebf30: 3ffec068 00000001 3ffe9a29 4020d538
3ffebf40: 00000bb8 3ffeab8e 00000004 00000000
3ffebf50: 3ffeab6c 00000016 3ffec068 4020ac3d
3ffebf60: 3ffe9a28 00000001 3ffec068 460ca000
3ffebf70: 3ffec068 00000015 3ffec068 4020d60c
3ffebf80: 3ffeab6c 3ffeab6c 3ffec068 4020d62d
3ffebf90: 4024d018 3ffeab6c 3ffec068 40202738
3ffebfa0: 9a01a8c0 00ffffff 0101a8c0 460ca000
3ffebfb0: 312e3033 3f000030 3ffec068 40202936
3ffebfc0: 3ffe9a78 9a01a8c0 00000000 00000000
3ffebfd0: 00000000 00000000 00000016 40101ec9
3ffebfe0: 40202129 00000000 00000000 3ffec03c
3ffebff0: 3fffdc20 00000000 3ffec034 40202186
3ffec000: 00000000 00000000 3ffeaff0 40100398
<<<stack<<<

ets Jan 8 2013,rst cause:2, boot mode:(1,7)

daemach
 
Posts: 143
Joined: Fri Feb 13, 2009 2:07 pm

Re: GroupSensors not working with ESP8266 - WDT crash on sec

by daemach on Sat Oct 31, 2015 12:02 pm

More info. It seems to be crashing on the second pass because it's trying to update subscriptions. On the first connect, it doesn't make it into this section. On the second pass it does - see my modified connect function with debug logging below to see what I mean. I have another debug print inside the subscribepacket function but we never get to that one. I wonder if one of the variables being passed in are corrupt somehow :

This is the first connect sequence:
MQTT connect packet:
[0x10], N [0x4E], [0x00], [0x04], M [0x4D], Q [0x51], T [0x54], T [0x54],
[0x04], Â [0xC2], [0x01], , [0x2C], [0x00], [0x0F], 1 [0x31], 5 [0x35],
: [0x3A], 1 [0x31], 6 [0x36], : [0x3A], 4 [0x34], 2 [0x32], d [0x64], a [0x61],
e [0x65], m [0x6D], a [0x61], c [0x63], h [0x68], [0x00], [0x07], d [0x64],
a [0x61], e [0x65], m [0x6D], a [0x61], c [0x63], h [0x68], [0x00], ( [0x28],
d [0x64], b [0x62], f [0x66], a [0x61], 3 [0x33], 8 [0x38], e [0x65], a [0x61],
1 [0x31], 3 [0x33], d [0x64], 6 [0x36], c [0x63], c [0x63], 4 [0x34], 4 [0x34],
e [0x65], 4 [0x34], 5 [0x35], e [0x65], 2 [0x32], 9 [0x39], f [0x66], f [0x66],
3 [0x33], 2 [0x32], 9 [0x39], b [0x62], f [0x66], c [0x63], e [0x65], 9 [0x39],
c [0x63], 0 [0x30], e [0x65], 3 [0x33], d [0x64], b [0x62], 0 [0x30], a [0x61],

sendPacket returned: 80
Read packet: [0x20], [0x02], [0x00], [0x00],
Post-readpacket
maxsubs5
Adafruit IO Connected!


This is the second connect sequence:

MQTT connect packet:
[0x10], N [0x4E], [0x00], [0x04], M [0x4D], Q [0x51], T [0x54], T [0x54],
[0x04], Â [0xC2], [0x01], , [0x2C], [0x00], [0x0F], 1 [0x31], 5 [0x35],
: [0x3A], 1 [0x31], 6 [0x36], : [0x3A], 4 [0x34], 2 [0x32], d [0x64], a [0x61],
e [0x65], m [0x6D], a [0x61], c [0x63], h [0x68], [0x00], [0x07], d [0x64],
a [0x61], e [0x65], m [0x6D], a [0x61], c [0x63], h [0x68], [0x00], ( [0x28],
d [0x64], b [0x62], f [0x66], a [0x61], 3 [0x33], 8 [0x38], e [0x65], a [0x61],
1 [0x31], 3 [0x33], d [0x64], 6 [0x36], c [0x63], c [0x63], 4 [0x34], 4 [0x34],
e [0x65], 4 [0x34], 5 [0x35], e [0x65], 2 [0x32], 9 [0x39], f [0x66], f [0x66],
3 [0x33], 2 [0x32], 9 [0x39], b [0x62], f [0x66], c [0x63], e [0x65], 9 [0x39],
c [0x63], 0 [0x30], e [0x65], 3 [0x33], d [0x64], b [0x62], 0 [0x30], a [0x61],

sendPacket returned: 80
Read packet: [0x20], [0x02], [0x00], [0x00],
Post-readpacket
maxsubs5
Pre-subscribePacket

Exception (9):
epc1=0x40206805 epc2=0x00000000 epc3=0x00000000 excvaddr=0x0038372e depc=0x00000000




Code: Select all | TOGGLE FULL SIZE
int8_t Adafruit_MQTT::connect() {
  // Connect to the server.
  if (!connectServer())
    return -1;

  // Construct and send connect packet.
  uint8_t len = connectPacket(buffer);
  if (!sendPacket(buffer, len))
    return -1;

  // Read connect response packet and verify it
  len = readPacket(buffer, 4, CONNECT_TIMEOUT_MS);
  DEBUG_PRINTLN("Post-readpacket");
  if (len != 4)
    return -1;
  if ((buffer[0] != (MQTT_CTRL_CONNECTACK << 4)) || (buffer[1] != 2))
    return -1;
  if (buffer[3] != 0)
    return buffer[3];
  DEBUG_PRINT("maxsubs");DEBUG_PRINTLN(MAXSUBSCRIPTIONS);
  // Setup subscriptions once connected.
  for (uint8_t i=0; i<MAXSUBSCRIPTIONS; i++) {
    // Ignore subscriptions that aren't defined.
    DEBUG_PRINTLN(subscriptions[i]);
    if (subscriptions[i] == 0) continue;
    DEBUG_PRINTLN("Pre-subscribePacket");
    //    DEBUG_PRINTLN(buffer);
    // Construct and send subscription packet.
    uint8_t len = subscribePacket(buffer, subscriptions[i]->topic, subscriptions[i]->qos);
    DEBUG_PRINTLN("Post-subscribePacket");
    if (!sendPacket(buffer, len))
      return -1;

    // Check for SUBACK if using MQTT 3.1.1 or higher
    // TODO: The Server is permitted to start sending PUBLISH packets matching the
    // Subscription before the Server sends the SUBACK Packet.
    // if(MQTT_PROTOCOL_LEVEL > 3) {
    //   len = readPacket(buffer, 5, CONNECT_TIMEOUT_MS);
    //   DEBUG_PRINT(F("SUBACK:\t"));
    //   DEBUG_PRINTBUFFER(buffer, len);
    //   if ((len != 5) || (buffer[0] != (MQTT_CTRL_SUBACK << 4))) {
    //     return 6;  // failure to subscribe
    //   }
    // }

  }

  return 0;
}

daemach
 
Posts: 143
Joined: Fri Feb 13, 2009 2:07 pm

Re: GroupSensors not working with ESP8266 - WDT crash on sec

by jwcooper on Wed Nov 04, 2015 12:22 am

There were some fixes in the last couple of days for groups. Are you still running into this issue?

jwcooper
 
Posts: 670
Joined: Tue May 01, 2012 9:08 pm

Re: GroupSensors not working with ESP8266 - WDT crash on sec

by daemach on Wed Nov 04, 2015 5:35 am

Yes, it's still broken. The problem is in the MQTT library and there have been no changes to that for 13 days. I was able to get it to post by bypassing the subscriptions section but it fails every time otherwise.

My device has been sending live data for the past week and there is still NO data showing up in the feed list. At this point nothing works.

Connecting to Adafruit IO... Adafruit IO Connected!

Sending:
Altitude,382.00
Temperature,82.00
Humidity,31.79
Temperature2,83.00
AirQuality,565.00
Pressure,30.12
Success!

daemach
 
Posts: 143
Joined: Fri Feb 13, 2009 2:07 pm

Re: GroupSensors not working with ESP8266 - WDT crash on sec

by jwcooper on Wed Nov 04, 2015 11:28 am

EDIT: NM, I see your other post stating the same as I just asked...we're looking into it.

Ok, we'll dig into it. Are you using pretty much exactly the sketch from this example?

https://github.com/adafruit/adafruit-io ... sensor.ino

And are you using an esp8266 breakout from Adafruit? Can you remove all sensors, and anything else attached, and try with exactly the above sketch (with your aio key, etc)?

jwcooper
 
Posts: 670
Joined: Tue May 01, 2012 9:08 pm

Re: GroupSensors not working with ESP8266 - WDT crash on sec

by daemach on Wed Nov 04, 2015 11:35 am

I used the huzzah to proto my new board which is custom. Can't remove any sensors. This is the relevant section from the state machine though, and I am getting a success message on every publish. I assume that is coming from a response from the server.

Code: Select all | TOGGLE FULL SIZE
case UPLOAD:

      // ping adafruit io a few times to make sure we remain connected
      if (! mqtt.ping(3)) {
        // reconnect to adafruit io
        if (! mqtt.connected())
          connect();
      }
      char sendbuffer[160];
      char numberbuffer[20];

      // add temp feed name
      strcpy(sendbuffer, "Altitude,");

      // add temp value
      dtostrf(int(altitude * 3.28084), 2, 2, numberbuffer);
      strcat(sendbuffer, numberbuffer);

      // add new line and humidity feed name
      strcat(sendbuffer, "\nTemperature,");
      // add temp value
      dtostrf(int((9 * Temp_current) / 5 + 32), 2, 2, numberbuffer);
      strcat(sendbuffer, numberbuffer);

      // add new line and humidity feed name
      strcat(sendbuffer, "\nHumidity,");
      // add temp value
      dtostrf(Hum_current, 2, 2, numberbuffer);
      strcat(sendbuffer, numberbuffer);

      // add new line and humidity feed name
      strcat(sendbuffer, "\nTemperature2,");
      // add temp value
      dtostrf(int((9 * Temp2_current) / 5 + 32), 2, 2, numberbuffer);
      strcat(sendbuffer, numberbuffer);

      // add new line and humidity feed name
      strcat(sendbuffer, "\nAirQuality,");
      // add temp value
      dtostrf(IAQ_current, 2, 2, numberbuffer);
      strcat(sendbuffer, numberbuffer);

      // add new line and humidity feed name
      strcat(sendbuffer, "\nPressure,");
      // add temp value
      dtostrf(inHg_current, 2, 2, numberbuffer);
      strcat(sendbuffer, numberbuffer);

      // Now we can publish stuff!
      Serial.println(F("\nSending: "));
      Serial.println(sendbuffer);

      if (! airQuality.publish(sendbuffer))
        Serial.println(F("Failed."));
      else
        Serial.println(F("Success!"));

      //      tft.print(" Alt:"); tft.print(int(altitude * 3.28084)); tft.println("ft");
      //      tft.print(" Tmp:"); tft.print(int(Temp_current)); tft.print("/"); tft.println(int((9 * Temp_current) / 5 + 32));
      //      tft.print("Tmp2:"); tft.print(int(Temp2_current));  tft.print("/"); tft.println(int((9 * Temp2_current) / 5 + 32));
      //      tft.print("Humi:"); tft.print(int(Hum_current)); tft.println("%");
      //      tft.print(" IAQ:"); tft.println(IAQ_current);
      //      tft.print("Baro:"); tft.println(inHg_current);
      //      tft.println();
      //      tft.print("Status:"); tft.println((IAQStatus != 0 ) ? "Cali" : "Live");


      lastUpload = millis();
      state = IDLE;



      break;

daemach
 
Posts: 143
Joined: Fri Feb 13, 2009 2:07 pm

Re: GroupSensors not working with ESP8266 - WDT crash on sec

by daemach on Wed Nov 04, 2015 11:37 am

BTW, the problem with using that example sketch is that I don't have the sensor the code is looking for... I would have to hack it to send some random data anyway so we're back to square one.

daemach
 
Posts: 143
Joined: Fri Feb 13, 2009 2:07 pm

Re: GroupSensors not working with ESP8266 - WDT crash on sec

by daemach on Wed Nov 04, 2015 11:45 am

One more thing - sorry :/ I had to break out of the the subscriptions code in the mqtt connect function to get this to work at all. If I don't, it fails every single time on the second pass then does a WDT reset or drops into bootloader mode. I left more info on the bug tracker.

Here is the connect function I'm using. (from Adafruit_MQTT.cpp)

Code: Select all | TOGGLE FULL SIZE
int8_t Adafruit_MQTT::connect() {
  // Connect to the server.
  if (!connectServer())
    return -1;

  // Construct and send connect packet.
  uint8_t len = connectPacket(buffer);
  if (!sendPacket(buffer, len))
    return -1;

  // Read connect response packet and verify it
  len = readPacket(buffer, 4, CONNECT_TIMEOUT_MS);
  DEBUG_PRINTLN("Post-readpacket");
  if (len != 4)
    return -1;
  if ((buffer[0] != (MQTT_CTRL_CONNECTACK << 4)) || (buffer[1] != 2))
    return -1;
  if (buffer[3] != 0)
    return buffer[3];
  DEBUG_PRINT("maxsubs");DEBUG_PRINTLN(MAXSUBSCRIPTIONS);
  // Setup subscriptions once connected.
  for (uint8_t i=0; i<MAXSUBSCRIPTIONS; i++) {
    // Ignore subscriptions that aren't defined.
      continue;  //  This section is broken!!!! Bypass....

    if (subscriptions[i] == 0) continue;
    DEBUG_PRINTLN("Pre-subscribePacket");
   
    // Construct and send subscription packet.
    uint8_t len = subscribePacket(buffer, subscriptions[i]->topic, subscriptions[i]->qos);
    DEBUG_PRINTLN("Post-subscribePacket");
    if (!sendPacket(buffer, len))
      return -1;

    // Check for SUBACK if using MQTT 3.1.1 or higher
    // TODO: The Server is permitted to start sending PUBLISH packets matching the
    // Subscription before the Server sends the SUBACK Packet.
    // if(MQTT_PROTOCOL_LEVEL > 3) {
    //   len = readPacket(buffer, 5, CONNECT_TIMEOUT_MS);
    //   DEBUG_PRINT(F("SUBACK:\t"));
    //   DEBUG_PRINTBUFFER(buffer, len);
    //   if ((len != 5) || (buffer[0] != (MQTT_CTRL_SUBACK << 4))) {
    //     return 6;  // failure to subscribe
    //   }
    // }

  }

  return 0;
}

daemach
 
Posts: 143
Joined: Fri Feb 13, 2009 2:07 pm

Re: GroupSensors not working with ESP8266 - WDT crash on sec

by tdicola on Thu Nov 05, 2015 6:03 pm

Can you post the full sketch code you're using? It does sound like something is adding a subscription and then the subscription loop logic gets tripped up trying to read data that hasn't been initialized (which could cause a reset, etc.). Let's check if there's anything in the sketch that could be changing the subscription state and hitting that logic. Thanks!

tdicola
 
Posts: 1074
Joined: Thu Oct 17, 2013 9:11 pm

Re: GroupSensors not working with ESP8266 - WDT crash on sec

by daemach on Thu Nov 05, 2015 6:43 pm

Code: Select all | TOGGLE FULL SIZE
#include <ESP8266WiFi.h>
#include "Adafruit_MQTT.h"
#include "Adafruit_MQTT_Client.h"
#include <Wire.h>
#include <SHT21.h>
#include "SparkFunMPL3115A2.h"
#include <Adafruit_GFX.h>    // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library
#include <SPI.h>


#define IDLE 1
#define SHT 2
#define IAQ 3
#define MPL 4
#define REFRESH 5
#define UPLOAD 6

// For the breakout, you can use any 2 or 3 pins
// These pins will also work for the 1.8" TFT shield
#define TFT_CS     15
#define TFT_RST    16  // you can also connect this to the Arduino reset
// in which case, set this #define pin to 0!
#define TFT_DC     2

/************************* WiFi Access Point *********************************/

#define WLAN_SSID       "myAP"
#define WLAN_PASS       "yahrite"

/************************* Adafruit.io Setup *********************************/

#define AIO_SERVER      "io.adafruit.com"
#define AIO_SERVERPORT  1883
#define AIO_USERNAME    "daemach"
#define AIO_KEY         "VALID AIO KEY"

/************ Global State (you don't need to change this!) ******************/

// Create an ESP8266 WiFiClient class to connect to the MQTT server.
WiFiClient client;

// Store the MQTT server, client ID, username, and password in flash memory.
// This is required for using the Adafruit MQTT library.
const char MQTT_SERVER[] PROGMEM    = AIO_SERVER;
// Set a unique MQTT client ID using the AIO key + the date and time the sketch
// was compiled (so this should be unique across multiple devices for a user,
// alternatively you can manually set this to a GUID or other random value).
const char MQTT_CLIENTID[] PROGMEM  = __TIME__ AIO_USERNAME;
const char MQTT_USERNAME[] PROGMEM  = AIO_USERNAME;
const char MQTT_PASSWORD[] PROGMEM  = AIO_KEY;

// Setup the MQTT client class by passing in the WiFi client and MQTT server and login details.
Adafruit_MQTT_Client mqtt(&client, MQTT_SERVER, AIO_SERVERPORT, MQTT_CLIENTID, MQTT_USERNAME, MQTT_PASSWORD);

/****************************** Feeds ***************************************/

//String serialNumber = String(ESP.getChipId()) + String(ESP.getFlashId());

// Setup a group called 'weather' for publishing changes.
// Notice MQTT group CSV paths for AIO follow the form: <username>/groups/<groupname>/csv
const char AQ_FEED[] PROGMEM = AIO_USERNAME "/groups/iaqmon/csv";
Adafruit_MQTT_Publish airQuality = Adafruit_MQTT_Publish(&mqtt, AQ_FEED);



// Option 1 (recommended): must use the hardware SPI pins
// (for UNO thats sclk = 13 and sid = 11) and pin 10 must be
// an output. This is much faster - also required if you want
// to use the microSD card (see the image drawing example)
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS,  TFT_DC, TFT_RST);

// Option 2: use any pins but a little slower!
#define TFT_SCLK 13   // set these to be whatever pins you like!
#define TFT_MOSI 11   // set these to be whatever pins you like!
//Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST);


float p = 3.1415926;



int state = 1;
float altitude = -999;
float IAQStatus = 16;

long IAQ_current = 0;
float Hum_current = 0;
float Temp_current = 0;
float Temp2_current = 0;
float inHg_current = 0;

float IAQ_last = 0;
float Hum_last = 0;
float Temp_last = 0;
float Temp2_last = 0;
float inHg_last = 0;


int deelay = 100;

unsigned long uploadTime = 15;  //in seconds
unsigned long lastUpload = 0;  //in seconds

long IAQ_data [4]; // data array


MPL3115A2 myPressure;

void setup() {
  Serial.begin(115200);
  Wire.begin();
  Wire.setClock(100000);  //Set clock speed to 100KHz for stability

  Serial.println("I live...");

  // Use this initializer (uncomment) if you're using a 1.8" TFT
  tft.initR(INITR_GREENTAB);   // initialize a ST7735S chip, green tab
  Serial.println("ST7735 TFT initialized!");

  tft.fillScreen(ST7735_BLACK);

  tft.setRotation(3);

  tft.setTextColor(ST7735_WHITE);
  tft.setTextSize(3);
  tft.setCursor(18, 50);
  tft.println("AirNode");

  myPressure.begin(); // Get sensor online

  //Configure the sensor
  myPressure.setModeAltimeter(); // Measure altitude above sea level in meters

  myPressure.setOversampleRate(64); // Set Oversample to the recommended 128
  myPressure.enableEventFlags(); // Enable all three pressure and temp event flags

  delay(2000);
  unsigned long start = millis();

  while ((altitude <= 0 | altitude > 9000) & millis() - start < 10000) {
    altitude = myPressure.readAltitude();
    yield();
  }

  if (altitude <= 0 | altitude > 9000) Serial.println("Bah - timed out :/");

  myPressure.setModeBarometer(); // Measure pressure in Pascals from 20 to 110 kPa

  Serial.print(F("Connecting to "));
  Serial.println(WLAN_SSID);

  WiFi.begin(WLAN_SSID, WLAN_PASS);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(F("."));
  }
  Serial.println();

  Serial.println(F("WiFi connected"));
  Serial.println(F("IP address: "));
  Serial.println(WiFi.localIP());


  connect();
  lastUpload = millis();
}

void loop() {
  // put your main code here, to run repeatedly:

  switch (state) {
    case REFRESH:
      Serial.println("I'm REFRESH");

      tft.setRotation(3);

      if (IAQ_current >= 2000) {

        tft.fillScreen(ST7735_RED);
      } else if (IAQ_current >= 1000 & IAQ_current < 2000) {

        tft.fillScreen(ST7735_YELLOW);
      } else {

        tft.fillScreen(ST7735_GREEN);
      }

      // screen is 128x160.  Font 2 = 12 pixels.

      if (IAQ_current > 5000) {
        tft.setCursor(45, 50);
        tft.setTextColor(ST7735_BLACK);
        tft.setTextSize(4);

        tft.print("OMG");
        tft.setCursor(1, 110);
        tft.setTextSize(1);
        tft.print("Offensive, Malodorous Gas!");
        tft.setTextSize(4);
        delay(2000);
        tft.fillScreen(ST7735_RED);
        tft.setCursor(50, 50);
        tft.print("WTF");
        tft.setCursor(30, 110);
        tft.setTextSize(1);
        tft.print("Where's The Fan???!!!");
        tft.setTextSize(4);
        delay(2000);
        tft.fillScreen(ST7735_RED);
        tft.setCursor(35, 50);
        tft.print("GTFO");
        tft.setCursor(20, 110);
        tft.setTextSize(1);
        tft.print("Got To Find Oxygen!!!");
        tft.setTextSize(4);

        for (int i = 0; i < 4; i++) {
          tft.invertDisplay(true);
          delay(500);
          tft.invertDisplay(false);
          delay(500);
        }

      } else {
        tft.setCursor(1, 2);
        tft.setTextColor(ST7735_BLACK);
        tft.setTextSize(2);

        tft.print(" Alt:"); tft.print(int(altitude * 3.28084)); tft.println("ft");
        tft.print(" Tmp:"); tft.print(int(Temp_current)); tft.print("/"); tft.println(int((9 * Temp_current) / 5 + 32));
        tft.print("Tmp2:"); tft.print(int(Temp2_current));  tft.print("/"); tft.println(int((9 * Temp2_current) / 5 + 32));
        tft.print("Humi:"); tft.print(int(Hum_current)); tft.println("%");
        tft.print(" IAQ:"); tft.println(IAQ_current);
        tft.print("Baro:"); tft.println(inHg_current);
        tft.println();
        tft.print("Status:"); tft.println((IAQStatus != 0 ) ? "Cali" : "Live");
      }


      state = IDLE;
      delay(deelay);
      break;
    case IDLE:
      Serial.println("I'm Idle");

      if (millis() - lastUpload >= uploadTime * 1000) {
        state = UPLOAD;
      } else {
        state = SHT;
      }


      delay(deelay);
      break;
    case SHT:
      Serial.print("SHT20 here --> ");
      SHT21.readSensor();
      Hum_current = SHT21.humi;
      Temp_current = SHT21.temp;

      Serial.print("Humidity(%RH): ");
      Serial.print(SHT21.humi, 1);
      Serial.print("     Temperature(C/F): ");
      Serial.print(SHT21.temp, 1);  Serial.print("/");
      Serial.println(((9 / 5)*SHT21.temp) + 32, 1);

      // 9/5 *C + 32
      state = IAQ;
      delay(deelay);
      break;
    case IAQ:
      Serial.print("IAQ-Core here --> ");
      read_IAQ(); // read iAQ-core
      Serial.println();
      state = MPL;
      delay(deelay);
      break;
    case MPL:
      {


        Serial.print("MPL here --> ");

        Serial.print("Altitude(M/ft):");
        Serial.print(altitude, 2);
        Serial.print("/");
        Serial.print(altitude * 3.28084, 2);

        float pressure = myPressure.readPressure();
        Serial.print(" Pressure(Pa):");
        Serial.print(pressure, 2);

        float temperature = myPressure.readTemp();
        Serial.print(" Temp(C):");
        Serial.print(temperature, 2);

        Temp2_current = temperature;

        //References:
        //Definition of "altimeter setting": http://www.crh.noaa.gov/bou/awebphp/definitions_pressure.php
        //Altimeter setting: http://www.srh.noaa.gov/epz/?n=wxcalc_altimetersetting
        //Altimeter setting: http://www.srh.noaa.gov/images/epz/wxcalc/altimeterSetting.pdf
        //Verified against Boulder, CO readings: http://www.crh.noaa.gov/bou/include/webpres.php?product=webpres.txt

        //const int station_elevation_ft = 5374; //Must be obtained with a GPS unit
        //float station_elevation_m = station_elevation_ft * 0.3048; //I'm going to hard code this
        const int station_elevation_m = 140; //Accurate for the roof on my house
        //1 pascal = 0.01 millibars
        pressure /= 100; //pressure is now in millibars

        float part1 = pressure - 0.3; //Part 1 of formula

        const float part2 = 8.42288 / 100000.0;
        float part3 = pow((pressure - 0.3), 0.190284);
        float part4 = (float)station_elevation_m / part3;
        float part5 = (1.0 + (part2 * part4));
        float part6 = pow(part5, (1.0 / 0.190284));
        float altimeter_setting_pressure_mb = part1 * part6; //Output is now in adjusted millibars
        float baroin = altimeter_setting_pressure_mb * 0.02953;

        Serial.print(" Altimeter setting InHg:");
        Serial.print(baroin, 2);

        inHg_current = baroin;

        Serial.println();

        state = REFRESH;
        delay(deelay);
      }
      break;

    case UPLOAD:

      // ping adafruit io a few times to make sure we remain connected
      if (! mqtt.ping(3)) {
        // reconnect to adafruit io
        if (! mqtt.connected())
          connect();
      }
      char sendbuffer[160];
      char numberbuffer[20];

      // add temp feed name
      strcpy(sendbuffer, "Altitude,");

      // add temp value
      dtostrf(int(altitude * 3.28084), 2, 2, numberbuffer);
      strcat(sendbuffer, numberbuffer);

      // add new line and humidity feed name
      strcat(sendbuffer, "\nTemperature,");
      // add temp value
      dtostrf(int((9 * Temp_current) / 5 + 32), 2, 2, numberbuffer);
      strcat(sendbuffer, numberbuffer);

      // add new line and humidity feed name
      strcat(sendbuffer, "\nHumidity,");
      // add temp value
      dtostrf(Hum_current, 2, 2, numberbuffer);
      strcat(sendbuffer, numberbuffer);

      // add new line and humidity feed name
      strcat(sendbuffer, "\nTemperature2,");
      // add temp value
      dtostrf(int((9 * Temp2_current) / 5 + 32), 2, 2, numberbuffer);
      strcat(sendbuffer, numberbuffer);

      // add new line and humidity feed name
      strcat(sendbuffer, "\nAirQuality,");
      // add temp value
      dtostrf(IAQ_current, 2, 2, numberbuffer);
      strcat(sendbuffer, numberbuffer);

      // add new line and humidity feed name
      strcat(sendbuffer, "\nPressure,");
      // add temp value
      dtostrf(inHg_current, 2, 2, numberbuffer);
      strcat(sendbuffer, numberbuffer);

      // Now we can publish stuff!
      Serial.println(F("\nSending: "));
      Serial.println(sendbuffer);

      if (! airQuality.publish(sendbuffer))
        Serial.println(F("Failed."));
      else
        Serial.println(F("Success!"));

      //      tft.print(" Alt:"); tft.print(int(altitude * 3.28084)); tft.println("ft");
      //      tft.print(" Tmp:"); tft.print(int(Temp_current)); tft.print("/"); tft.println(int((9 * Temp_current) / 5 + 32));
      //      tft.print("Tmp2:"); tft.print(int(Temp2_current));  tft.print("/"); tft.println(int((9 * Temp2_current) / 5 + 32));
      //      tft.print("Humi:"); tft.print(int(Hum_current)); tft.println("%");
      //      tft.print(" IAQ:"); tft.println(IAQ_current);
      //      tft.print("Baro:"); tft.println(inHg_current);
      //      tft.println();
      //      tft.print("Status:"); tft.println((IAQStatus != 0 ) ? "Cali" : "Live");


      lastUpload = millis();
      state = IDLE;



      break;


    default:
      state = IDLE;
      break;
  }
}

void read_IAQ()
{
  Wire.requestFrom(90, 9);
  delay(500);
  if (Wire.available())
  {
    // read CO2 prediction
    IAQ_data[0] = long(Wire.read());
    IAQ_data[0] = IAQ_data[0] << 8;
    IAQ_data[0] += long(Wire.read());

    IAQ_current = IAQ_data[0];

    // read status
    IAQ_data[1] = long(Wire.read());

    IAQStatus = IAQ_data[1];

    // read  resistance
    IAQ_data[2] = long(Wire.read());
    IAQ_data[2] = IAQ_data[2] << 8;
    IAQ_data[2] += long(Wire.read());
    IAQ_data[2] = IAQ_data[2] << 8;
    IAQ_data[2] += long(Wire.read());
    IAQ_data[2] = IAQ_data[2] << 8;
    IAQ_data[2] += long(Wire.read());

    // read TVOC prediction
    IAQ_data[3] = long(Wire.read());
    IAQ_data[3] = IAQ_data[0] << 8;
    IAQ_data[3] += long(Wire.read());

    Wire.endTransmission(false);

    Serial.print(IAQ_data[0]);  // prediction
    Serial.print(" ");
    Serial.print(IAQ_data[1]);  // status byte
    Serial.print(" ");
    Serial.print(IAQ_data[2]);  // resistance
    Serial.print(" ");
    Serial.print(IAQ_data[3]);  // TVOC
  }
  else
  {
    Serial.print(" no data ");
  }
}

// connect to adafruit io via MQTT
void connect() {

  Serial.print(F("Connecting to Adafruit IO... "));

  int8_t ret;

  while ((ret = mqtt.connect()) != 0) {
    Serial.print(F("Farking "));
    switch (ret) {
      case 1: Serial.println(F("Wrong protocol")); break;
      case 2: Serial.println(F("ID rejected")); break;
      case 3: Serial.println(F("Server unavail")); break;
      case 4: Serial.println(F("Bad user/pass")); break;
      case 5: Serial.println(F("Not authed")); break;
      case 6: Serial.println(F("Failed to subscribe")); break;
      default: Serial.println(F("Connection failed")); break;
    }

    if (ret >= 0)
      mqtt.disconnect();

    Serial.println(F("Retrying connection..."));
    delay(5000);

  }

  Serial.println(F("Adafruit IO Connected!"));

}

daemach
 
Posts: 143
Joined: Fri Feb 13, 2009 2:07 pm

Re: GroupSensors not working with ESP8266 - WDT crash on sec

by jwcooper on Sun Nov 08, 2015 5:44 pm

I see another error being thrown for your use case in our logs. Working on it, but likely won't be fixed until Monday.

jwcooper
 
Posts: 670
Joined: Tue May 01, 2012 9:08 pm

Re: GroupSensors not working with ESP8266 - WDT crash on sec

by daemach on Sun Nov 08, 2015 6:22 pm

Thanks for working on it. I'm stuck in the mud at the moment :/

daemach
 
Posts: 143
Joined: Fri Feb 13, 2009 2:07 pm

Re: GroupSensors not working with ESP8266 - WDT crash on sec

by tdicola on Mon Nov 09, 2015 2:48 am

One thing too are you sure you aren't hitting memory limits of the ESP8266? I can't track down the SHT21.h library to really compile the sketch, but just commenting the SHT21.h include and its usage out I see the IDE reporting about 60% of dynamic memory used. If you get a few functions deep into the stack or have some recursion it could be getting close to the variables and causing odd behavior like you see (like memory appearing to get corrupted in some way). If you pull out a few of the sensors and other bits and try things one by one (i.e. just try with the display, then add in a sensor, etc.) do you see it change the behavior? That can help troubleshoot if it's a memory issue you're hitting.

tdicola
 
Posts: 1074
Joined: Thu Oct 17, 2013 9:11 pm

Re: GroupSensors not working with ESP8266 - WDT crash on sec

by daemach on Mon Nov 09, 2015 12:49 pm

Pretty sure. It happens the same way every time no matter how I move things around in the code. If I bypass that section it works fine. I have tried fewer sensors too.

daemach
 
Posts: 143
Joined: Fri Feb 13, 2009 2:07 pm

Re: GroupSensors not working with ESP8266 - WDT crash on sec

by daemach on Mon Nov 09, 2015 7:06 pm

Any news on this? I have the module attempting to send data regularly. I'm going to keep it running so you have something live to test with.

daemach
 
Posts: 143
Joined: Fri Feb 13, 2009 2:07 pm

Please be positive and constructive with your questions and comments.