Hi all, I’m not the greatest coder and would appreciate some help as to why I’m getting this SOS assert failure on my Photon running version 0.7. The assert failure basically kills my ability to do anything with the device until I run “particle doctor”. The assert failure occurs once I run the Particle.publish to read my webhook.
My code reads a JSON API and depending on the values on the webhook it changes the RGB value of 2 RGB LEDS. The webhook URL Is here: http://192.241.149.199:3000/device/ and my code is below.
Thank you!
// This #include statement was automatically added by the Particle IDE.
#include <ArduinoJson.h>
const char* HOUSE_A = "34003b000547363339343638";
const char* HOUSE_B = "3a0033000b47363339343638";
const char* HOUSE_C = "320061000d51353532343635";
int PriceRedPin = A4; // RED pin of the LED to PWM pin **A4**
int PriceGreenPin = D0; // GREEN pin of the LED to PWM pin **D0**
int PriceBluePin = D1; // BLUE pin of the LED to PWM pin **D1**
int ConsumptionRedPin = A5; // RED pin of the LED to PWM pin **A4**
int ConsumptionGreenPin = TX; // GREEN pin of the LED to PWM pin **D0**
int ConsumptionBluePin = RX; // BLUE pin of the LED to PWM pin **D1**
int PriceRedValue = 0; // Full brightness for an Cathode RGB LED is 0, and off 255
int PriceGreenValue = 0; // Full brightness for an Cathode RGB LED is 0, and off 255
int PriceBlueValue = 0; // Full brightness for an Cathode RGB LED is 0, and off 255
int ConsumptionRedValue = 0; // Full brightness for an Cathode RGB LED is 0, and off 255
int ConsumptionGreenValue = 0; // Full brightness for an Cathode RGB LED is 0, and off 255
int ConsumptionBlueValue = 0; // Full brightness for an Cathode RGB LED is 0, and off 255</td>
void setup() {
WiFi.disconnect();
WiFi.on();
WiFi.setCredentials("Frugar", "906EBB2D43AD");
Particle.subscribe("hook-response/getdata", getdata, MY_DEVICES);
// Set up our pins for output
pinMode( PriceRedPin, OUTPUT);
pinMode( PriceGreenPin, OUTPUT);
pinMode( PriceBluePin, OUTPUT);
pinMode( ConsumptionRedPin, OUTPUT);
pinMode( ConsumptionGreenPin, OUTPUT);
pinMode( ConsumptionBluePin, OUTPUT);
// turn them all off...
analogWrite( PriceRedPin, PriceRedValue);
analogWrite( PriceGreenPin, PriceGreenValue);
analogWrite( PriceBluePin, PriceBlueValue);
analogWrite( ConsumptionRedPin, ConsumptionRedValue);
analogWrite( ConsumptionGreenPin, ConsumptionGreenValue);
analogWrite( ConsumptionBluePin, ConsumptionBlueValue);
}
void getdata(const char *name, const char *data) { // we're subscribed to a webhook event in the particle console. You'll need to set this up in your console
String s = String(data);
unsigned int n = s.length();
char json[n];
strcpy(json, s); //cleaning up some json
DynamicJsonBuffer jsonBuffer;
JsonObject& root = jsonBuffer.parseObject(json);
if (!root.success()) {
//Serial.println("parseObject() failed");
return;
}
const char* colorA = root["colora"];
const char* colorB = root["colorb"];
const char* colorC = root["colorc"];
const char* priceColor = root["pricecolor"];
PriceLedControl(priceColor);
String coreID = System.deviceID();
if (coreID == HOUSE_A)
{
ConsumptionLedControl(colorA);
}
else if (coreID == HOUSE_B)
{
ConsumptionLedControl(colorB);
}
else if (coreID == HOUSE_C)
{
ConsumptionLedControl(colorC);
}
else
{
ConsumptionLedControl("255,255,255");
}
}
int PriceLedControl( String command )
{
String colors[3];
colors[0]="";
colors[1]="";
colors[2]="";
int index = 0;
for( int i = 0; i < command.length(); i++ )
{
if( index < 3 ){
char c = command.charAt(i);
colors[index] += c;
if( c == ',') index++;
}
}
// get the red component...
PriceRedValue = colors[0].toInt();
// now green
PriceGreenValue = colors[1].toInt();
// now blue
PriceBlueValue = colors[2].toInt();
// write the mixed color
analogWrite( PriceRedPin, PriceRedValue);
analogWrite( PriceGreenPin, PriceGreenValue);
analogWrite( PriceBluePin, PriceBlueValue);
return 1;
}
int ConsumptionLedControl( String command )
{
String colors[3];
colors[0]="";
colors[1]="";
colors[2]="";
int index = 0;
for( int i = 0; i < command.length(); i++ )
{
if( index < 3 ){
char c = command.charAt(i);
colors[index] += c;
if( c == ',') index++;
}
}
// get the red component...
ConsumptionRedValue = colors[0].toInt();
// now green
ConsumptionGreenValue = colors[1].toInt();
// now blue
ConsumptionBlueValue = colors[2].toInt();
// write the mixed color
analogWrite( ConsumptionRedPin, ConsumptionRedValue);
analogWrite( ConsumptionGreenPin, ConsumptionGreenValue);
analogWrite( ConsumptionBluePin, ConsumptionBlueValue);
return 1;
}
void loop(){
while (WiFi.ready()){
//if(abs(Time.minute() - lastTime) >= 5){ // if it's been mmore than five minutes
Particle.publish("getdata", PRIVATE);
delay(30000);
}
//}
}