Red flashes - Xenon 1.3.0-rc.1 - Assertion Error?

@Jimmie, help us to help you - If I take the code you have posted copy it to the IDE - it will not compile as it is incomplete.

Put your self in my position - I would love to help you, since when I started coding, I realised that a community can add so much to my skills, however in this case I cannot guess the rest of the code and therefore can add little value to your issue

1 Like

To avoid buffer overflow Iā€™d suggest you always use the n version of the string functions (e.g. snprintf() vs. sprintf()).

And assuming you donā€™t really need these indermediate variables (comType, ID, numBufX) and hence Iā€™d ā€œcollapseā€ your code block from above into a single command

  snprintf(data, sizeof(data)
          , "$,%i,%07i,%03i,%03i,%03i,%03i,^"
          , msgVal
          , lTruckID
          , tIn
          , tWIn
          , scanNum
          , offCV
          );

If you however need these intermediates you can replace the numeric format place holders with %s and the numeric variables with the intermediates.

Thank you @ScruffR. I have changed the code and will try it.

Thank you @shanevanj. I appreciate your time and help. Indeed, I have learned a lot from the communityā€™s input when the full code is shared. It is just that in this case, I was only able to share the code I included.

To reiterate what I said earlier

We now know the size of your array but from your code I can only see that you trust that scanNum will never ever exceed 99 and mySegment will never go beyond 15.
While I admire your trust :wink: , solid coding would actually ensure the limits won't be violated.

Hello @ScruffR,

Yes, this is solid advice. In my case, mySegment is limited by the hardware to 15, scanNum is indeed limited by another (unlisted) part of the code which causes a break once scanNum approaches 80.

The code running without a problem on the Photon primarily lacks the sendMessage() sub so I will implement your code recommendations to see if it was the culprit.

Thank again for your time and advice.

1 Like

Thanks for the suggestions and fixes on my change. I changed the routine to use micros() instead and eliminated the decimal point error. The code compiles fine, and does not fix the problem at all. I was simple trying to eliminate the delay() routines in the acquire function to see if this was causing the code not to work. I am still trying to get the DHT22 working again. Is there a good reference on how to downgrade the OS back to a stable version? I cant seem to find a step by step example. Any suggestion would be appreciated.

My Changed Function:

int PietteTech_DHT::acquire() {
    // Check if sensor was read less than two seconds ago and return early
    // to use last reading
    unsigned long currenttime = millis();
    unsigned long DHT22period = 1500;
    unsigned long DHT11period = 1800;
    unsigned long time_now = 0;
   
    if (currenttime < _lastreadtime) {
        // there was a rollover
        _lastreadtime = 0;
    }
    if (!_firstreading && ((currenttime - _lastreadtime) < 2000 )) {
        // return last correct measurement, (this read time - last read time) < device limit
        return DHTLIB_ACQUIRED;
    }

    if (_state == STOPPED || _state == ACQUIRED) {
        /*
         * Setup the initial state machine
         */
        _firstreading = false;
        _lastreadtime = currenttime;
        _state = RESPONSE;

#if defined(DHT_DEBUG_TIMING)
        /*
         * Clear the debug timings array
         */
        for (int i = 0; i < 41; i++) _edges[i] = 0;
        _e = &_edges[0];
#endif

        /*
         * Set the initial values in the buffer and variables
         */
        for (int i = 0; i < 5; i++) _bits[i] = 0;
        _cnt = 7;
        _idx = 0;
        _hum = 0;
        _temp = 0;

        /*
         * Toggle the digital output to trigger the DHT device
         * to send us temperature and humidity data
         */
        pinMode(_sigPin, OUTPUT);
        digitalWrite(_sigPin, LOW);
     
        
        if (_type == DHT11)
           
         {     
               
               
  
         time_now = micros();
          while(micros() < time_now + DHT11period)
          {
        //wait approx. [1.5] ms
          }
         }
         
            //delayMicroseconds(1800);                  // DHT11 Spec: 18ms min
        else
        
       
          time_now = micros();
          while(micros() < time_now + DHT22period)
          {
        //wait approx. [1.5] ms
          }    
            //delayMicroseconds(1500);    // DHT22 Spec: 0.8-20ms, 1ms typ
        pinMode(_sigPin, INPUT);        // Note Hi-Z mode with pullup resistor
                                        // will keep this high until the DHT responds.
        /*
         * Attach the interrupt handler to receive the data once the DHT
         * starts to send us data
         */
        _us = micros();
        //Serial.print("Exiting Routine\n");
        attachInterrupt(_sigPin, &PietteTech_DHT::_isrCallback, this, FALLING);
        

        return DHTLIB_ACQUIRING;
    } else
        return DHTLIB_ERROR_ACQUIRING;
}

Hello @HillBilly:

I followed the advice here:

I hope that by downgrading firmware your problem will be solved. However, I have had lots of problems with the mesh devices (including this post), and also issues with serial ports and Ethernet/SD interference.

As much as I am impressed with the specs of this platform, I have decided to abandon my efforts and revert to finding alternatives using Particle's legacy hardware.

Thanks for the feedback guys. I am still having trouble getting a xenon to flash with the serial debugger on windows 64. It either times out at 70000ms or just sits there saying it is sending the bin file. It also blinks in safe mode while it thinks it is sending the file. I am new to using Particle stuff so I will have to keep at it until I figure out a way to revert back to a OS that works with the DHT sensors.

Hello @HillBilly,

I had a similar problem a few months ago. On the advice of @ScruffR, I first flashed the sketch below and it allowed me to start fresh ā€¦

#include "application.h"
#include "string_convert.h"
#include "dct.h"
 
 SYSTEM_MODE(SEMI_AUTOMATIC);

void setup() {
    const uint8_t val = 0x01;
    dct_write_app_data(&val, DCT_SETUP_DONE_OFFSET, 1);

    // This is just so you know the operation is complete
    pinMode(D7, OUTPUT);
    digitalWrite(D7, HIGH);
}

Thanks Jimmie,
I was able to flash 1.2.1 back on a Xenon using the USB debugger module. Thanks goodness for JTAG. I reloaded my DHT code I am playing with and had the same SOS red blinking message. It appears to me that somewhere between 1.1.1 and 1.2.1 the DHT example quit working. I am going to try and get a simpler version of the code working by stripping it down to be specific for the DHT22 module. I think it has something to do with how the OS handles Interrupts on the new version, but I am just guessing. Thanks for all the support from the Community. Parallel minds solve problems quicker :slight_smile:

1 Like

No need for guessing. The comments in the issue I linked you to quite some time ago does explain exactly what the cause is.

Hi All,
Just wanted to post an update to everyone to inform that I ended up switching over to a different library to get my DHT22 sensors working for now. The code posted below works with OS version 1.2.1 on a XENON and is a simple cut and paste to test functionality. It is not cleaned up by far yet so please keep in mind it was just a hack. I will update it and simplify it when I can. My goal was to get the DHT22 working reliably again ASAP. Hopefully this will save someone else time that I spent debugging it.

// This #include statement was automatically added by the Particle IDE.
#include <SparkFunRHT03.h>

/////////////////////
// Pin Definitions //
/////////////////////
const int RHT03_DATA_PIN = D2; // RHT03 data pin
const int LIGHT_PIN = A0; // Photocell analog output
const int LED_PIN = D7; // LED to show when the sensor's are being read

///////////////////////////
// RHT03 Object Creation //
///////////////////////////
RHT03 rht; // This creates a RTH03 object, which we'll use to interact with the sensor

unsigned int minimumLight = 65536;
unsigned int maximumLight = 0;
float minimumTempC = 5505;
float maximumTempC = 0;
float minimumTempF = 9941;
float maximumTempF = 0;
float minimumHumidity = 100;
float maximumHumidity = 0;
int period = 1000;
unsigned long time_now = 0;


void setup() 
{
    // Serial.begin() is used to open up a serial interface between the Photon
    // and your computer.
    // The '9600' parameter configures the speed of the interface. This value is
    // called the "baud rate", which is equivalent to bits per second (bps).
    Serial.begin(9600); // Start the serial interface at 9600 bps
    
    // Using the 'rht' object created in the global section, we'll begin by calling
    // its member function `begin`.
    // The parameter in this function is the DIGITAL PIN we're using to communicate
    // with the sensor.
    rht.begin(RHT03_DATA_PIN);  // Initialize the RHT03 sensor
    
    // Don't forget to set the pin modes of our analog sensor (INPUT) and the LED (OUTPUT):
   // pinMode(LIGHT_PIN, INPUT); // Set the photocell pin as an INPUT.
 //   pinMode(LED_PIN, OUTPUT); // Set the LED pin as an OUTPUT
    digitalWrite(LED_PIN, LOW); // Initially set the LED pin low -- turn the LED off.
}

void loop() 
{
    digitalWrite(LED_PIN, HIGH); // Turn the LED on -- it'll blink whenever the sensor is being read.
    
    // Use the RHT03 member function `update()` to read new humidity and temperature values from the sensor.
    // There's a chance the reading might fail, so `update()` returns a success indicator. It'll return 1
    // if the update is successful, or a negative number if it fails.
    int update = rht.update();
    
    if (update == 1) // If the update succeeded, print out the new readings:
    {
        // Use analogRead to get the latest light sensor reading:
        unsigned int light = analogRead(LIGHT_PIN);
        // Do some math to calculate the minimum and maximum light sensor readings we've seen:
        if (light > maximumLight) maximumLight = light;
        if (light < minimumLight) minimumLight = light;
        
        // The `humidity()` RHT03 member function returns the last successfully read relative
        // humidity value from the RHT03.
        // It'll return a float value -- a percentage of RH between 0-100.
        // ONLY CALL THIS FUNCTION AFTER SUCCESSFULLY RUNNING rht.update()!.
        float humidity = rht.humidity();
        // Do some math to calculate the max/min humidity
        if (humidity > maximumHumidity) maximumHumidity = humidity;
        if (humidity < minimumHumidity) minimumHumidity = humidity;
        
        // The `tempF()` RHT03 member function returns the last succesfully read 
        // farenheit temperature value from the RHT03.
        // It returns a float variable equal to the temperature in Farenheit.
        // ONLY CALL THIS FUNCTION AFTER SUCCESSFULLY RUNNING rht.update()!.
        float tempF = rht.tempF();
        // Do some math to calculate the max/min tempF
        if (tempF > maximumTempF) maximumTempF = tempF;
        if (tempF < minimumTempF) minimumTempF = tempF;
        Particle.publish("Temperature", String(tempF) + " Ā°F");
        Particle.publish("Humidity", String(humidity) + "%");

 
    }
    else // If the update failed, give the sensor time to reset:
    {
        Serial.println("Error reading from the RHT03."); // Print an error message
        Serial.println(); // Print a blank line
        
        time_now = millis(); // get current millis count
        while(millis() < time_now + (period*2))
        {
        //Wait for 5000 ms
        }
        
       // delay(RHT_READ_INTERVAL_MS); // The RHT03 needs about 1s between read attempts
    }
    digitalWrite(LED_PIN, LOW); // Turn the LED off
    
    //delay(PRINT_RATE); // delay for 1s, printing too much will make the output very hard to read.
}
1 Like