It is a communication error, but I was wondering why does it fall into that state when it can’t get to the internet. Granted it is some interaction with the Neopixel code in a thread that gets it to that state.
I can reproduce it by disabling my wifi, blocking the particle at the firewall and then enable the wifi.
But I was with the serial debugging able to get my ISR watchdog to work to reset it.
The program is here, I am throwing the kitchen sink at it because I wanted to see how stable it was before spending to much time on it, because arduino’s always seem to die at some point if there is any network code.
Is this the code I am getting? def_panic_codes(Faults,RGB_COLOR_RED,HardFault)
#include "Adafruit_SSD1306.h"
#include "Adafruit_GFX.h"
#include "neopixel.h"
#include "SparkTime.h"
#include "application.h"
#include "SparkIntervalTimer.h"
Thread* led1Thread;
// If using software SPI (the default case):
#define OLED_MOSI D0
#define OLED_CLK D1
#define OLED_DC D2
#define OLED_CS D3
#define OLED_RESET D4
Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);
IntervalTimer myTimer;
IPAddress localIP;
volatile unsigned long WatchDogCount = 0; // use volatile for variables shared with ISR
SYSTEM_MODE(AUTOMATIC);
// IMPORTANT: Set pixel COUNT, PIN and TYPE
#define PIXEL_PIN D6
#define PIXEL_COUNT 12
#define PIXEL_TYPE WS2812
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);
UDP UDPClient;
SparkTime rtc;
TCPServer server = TCPServer(23);
TCPClient client;
char addr[32];
char incoming;
typedef struct {
int pin;
int delay;
} LED_PARAM;
// LED pins
int led1 = D5;
int led2 = D3;
int led3 = D1;
LED_PARAM ledParams[3] = {
{led1, 20},
{led2, 1000},
{led3, 2000}
};
void rainbow_thread(void* param) {
Serial.println("+rainbow_thread(void* param)");
LED_PARAM *p = (LED_PARAM*)param;
for(;;) {
//Serial.println("Thread Parameters: ");
//Serial.println(p->pin);
//Serial.println(", ");
//Serial.printlnln(p->delay);
rainbow(20);
delay(10);
}
//rainbow(20);
Serial.println("-rainbow_thread(void* param)");
}
void rainbow(uint8_t wait) {
Serial.println("+rainbow(uint8_t wait)");
uint16_t i, j;
for(j=0; j<256; j++) {
for(i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel((i+j) & 255));
}
// XXX DISABLE FOR NOW
Serial.println("+strip.show();");
strip.show();
Serial.println("-strip.show();");
delay(wait);
}
Serial.println("-rainbow(uint8_t wait)");
}
// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
//Serial.println("+Wheel(byte WheelPos)");
if(WheelPos < 85) {
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
} else if(WheelPos < 170) {
WheelPos -= 85;
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
} else {
WheelPos -= 170;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
//Serial.println("-Wheel(byte WheelPos)");
}
void display_time(int aliveTicks) {
Serial.println("+display_time()");
unsigned long currentTime;
char output[128];
uint32_t freemem = System.freeMemory();
currentTime = rtc.now();
uint8_t min = rtc.minute(currentTime);
uint8_t hour = rtc.hour(currentTime);
uint8_t sec = rtc.second(currentTime);
display.clearDisplay();
sprintf(output, "%02d:%02d:%02d", hour,min,sec);
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(0,0);
display.println(output);
sprintf(output, "%d", aliveTicks);
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(0,40);
display.println(output);
display.display();
Serial.println("-display_time()");
}
void check_tcp() {
Serial.println("+check_tcp()");
client = server.available();
if (client.connected()) {
unsigned long currentTime;
char output[128];
currentTime = rtc.now();
uint8_t min = rtc.minute(currentTime);
uint8_t hour = rtc.hour(currentTime);
uint8_t sec = rtc.second(currentTime);
sprintf(output, "%02d:%02d:%02d", hour,min,sec);
client.println("Connected to Spark!");
client.println(WiFi.localIP());
client.println(WiFi.subnetMask());
client.println(WiFi.gatewayIP());
client.println(WiFi.SSID());
client.println(output);
client.stop();
/*
while (client.connected()) {
while (client.available()) {
incoming = client.read();
client.write(incoming); // great to show on telnet what has been printed
//if (incoming == 'A'){ digitalWrite(D7, HIGH); }
//if (incoming == 'B'){ digitalWrite(D7, LOW); }
}
}
*/
}
Serial.println("-check_tcp()");
}
void UpISR(void) {
Serial.println("+UpISR(void) 205");
char output[128];
Serial.println("+UpISR(void) 208");
if(System.updatesPending()) {
myTimer.interrupt_SIT(INT_DISABLE); // Stop
System.enableUpdates();
display.clearDisplay();
sprintf(output, ".UPDATING.");
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(0,20);
display.println(output);
display.display();
//delay(2000);
Serial.println("+UpISR(void) 2224");
return;
}
Serial.println("+UpISR(void) 227");
WatchDogCount++; // increase when LED turns changes
Serial.println(WatchDogCount);
Serial.println("+UpISR(void) 230");
if (WatchDogCount>100) {
Serial.println("-UpISR(void) LOCKUP");
System.reset();
} else {
sprintf(output, "%u", WatchDogCount);
}
Serial.println("+UpISR(void) 236");
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(0,20);
display.println(output);
Serial.println("-UpISR(void) 241");
}
void setup() {
Serial.println("+setup()");
Serial.begin(9600);
Serial.println("NO FORMAT");
rtc.begin(&UDPClient, "north-america.pool.ntp.org");
rtc.setTimeZone(-5);
strip.begin();
strip.show(); // Initialize all pixels to 'off'
// init display
display.begin(SSD1306_SWITCHCAPVCC);
display.clearDisplay();
myTimer.begin(UpISR, 1000, hmSec);
//display.setTextSize(1);
//display.setTextColor(WHITE);
//display.setCursor(0,0);
//display.println("...");
//display.println(":");
//display.setTextSize(2);
//display.setCursor(128 / 2 -(12 * 6) / 2, 32);
//display.println("");
//display.display();
unsigned long currentTime;
currentTime = rtc.nowNoUpdate();
server.begin();
IPAddress localIP = WiFi.localIP();
sprintf(addr, "%u.%u.%u.%u", localIP[0], localIP[1], localIP[2], localIP[3]);
if (Particle.connected()) {
Particle.variable("Address", addr, STRING);
}
led1Thread = new Thread("RainbowLed", rainbow_thread,&ledParams[0]);
System.disableUpdates(); // Update in the ISR
Serial.println("-setup()");
}
int aliveTicks = 0;
void loop() {
Serial.println("+loop()");
//
//display_time();
//rainbow(20);
WatchDogCount=0;
display_time(aliveTicks);
delay(200);
aliveTicks=aliveTicks+1;
if (Particle.connected()) {
check_tcp();
localIP = WiFi.localIP();
sprintf(addr, "%u.%u.%u.%u %u", localIP[0], localIP[1], localIP[2], localIP[3],aliveTicks);
Particle.variable("Address", addr, STRING);
}
Serial.println("-loop()");
}