Argon+mesh is disconnecting/unreachable from the Particle Cloud frequently

Greetings,

setup is argon+mesh, but I don’t have devices yet for mesh like xenon, it’s just for trial… but, argon keep disconnecting from wifi after 30~40minutes. I am not sure how to debug this… the only message I can see is from the console Device Vitals

I am sure there are no heavy workloads inside argons, it just checks temp from DHT11, and store it in Particle.variable and some simple Particle.function that lits up LED lights from the example.

The device is disconnecting from the Particle Cloud too frequently. Large numbers of cloud disconnects are often caused by poor signal strength or network congestion. If possible, move the device to a place with better Cellular signal.

I already check this thread, I don’t think have heavy tasks… I can share the code…

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

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

int led1 = D0; // Instead of writing D0 over and over again, we'll write led1
int led2 = D7; // Instead of writing D7 over and over again, we'll write led2
int pos = 0;   
int led3 = D1;
Servo myservo;  // create servo object to control a servo


 // system defines
#define DHTTYPE  DHT11            // Sensor type DHT11/21/22/AM2301/AM2302
#define DHTPIN   D10          	    // Digital pin for communications
#define DHT_SAMPLE_INTERVAL   2000  // Sample every two seconds
PietteTech_DHT DHT(DHTPIN, DHTTYPE);

int CLK = D13; //Set the CLK pin connection to the display
int DIO = D12; //Set the DIO pin connection to the display

int NumStep = 0;  //Variable to interate
int currentTemp = 0;
int currentHumid = 0;

TM1637Display display(CLK, DIO);  //set up the 4-Digit Display.

void setup() {
    myservo.attach(D5);
    Serial.begin(9600);
    Serial.println("starting..");
    
    pinMode(led1, OUTPUT);
    pinMode(led2, OUTPUT);
    pinMode(led3, OUTPUT);
    
    Particle.function("led", ledToggle);
    Particle.function("feedFish", feedFish);
    Particle.function("feedFish2", feedFishReset);
    Particle.variable("currentTemp", currentTemp);
    Particle.variable("currentHumid", currentHumid);

    display.setBrightness(0x0a);  //set the diplay to maximum brightness
    display.showNumberDec(0);
}

void loop() {
    retrvTempAndSave();
}

int retrvTempAndSave() {
    int defTemp = 0;
    int result = DHT.acquireAndWait(1000); // wait up to 1 sec (default indefinitely)
    
    switch (result) {
        case DHTLIB_OK:
            {
                Serial.println("OK");
                currentHumid = (int)DHT.getHumidity();
                currentTemp = (int)DHT.getCelsius();
                

                display.showNumberDec(currentTemp);
                Particle.publish("azure-temp", String(currentTemp), PRIVATE);
                
                String data = String::format("{ \"tags\" : {\"id\": \"%s\"},\"values\": {\"temp\": %i, \"humidity\": %i}}", "beee-11-30-2", currentTemp, currentHumid);
                Particle.publish("influx-particle-io", data, PRIVATE);
            }
            
            return defTemp;
            // break;
        case DHTLIB_ERROR_CHECKSUM:
            Serial.println("Error\n\r\tChecksum error");
            break;
        case DHTLIB_ERROR_ISR_TIMEOUT:
            Serial.println("Error\n\r\tISR time out error");
            break;
        case DHTLIB_ERROR_RESPONSE_TIMEOUT:
            Serial.println("Error\n\r\tResponse time out error");
            break;
        case DHTLIB_ERROR_DATA_TIMEOUT:
            Serial.println("Error\n\r\tData time out error");
            break;
        case DHTLIB_ERROR_ACQUIRING:
            Serial.println("Error\n\r\tAcquiring");
            break;
        case DHTLIB_ERROR_DELTA:
            Serial.println("Error\n\r\tDelta time to small");
            break;
        case DHTLIB_ERROR_NOTSTARTED:
            Serial.println("Error\n\r\tNot started");
            break;
        default:
            Serial.println("Unknown error");
            break;
    }
    delay(1000);
    return defTemp;
}

int getTemp() {
    
}

int feedFish(String pos) {
    myservo.write(pos.toInt());
}

int feedFishReset(String pos) {
    myservo.write(pos.toInt());
    delay(800);
    myservo.write(0);
}

int ledToggle(String command) {

    if (command=="on") {
        // digitalWrite(led1,HIGH);
        // digitalWrite(led2,HIGH);
        digitalWrite(led3, HIGH);
        return 1;
    }
    else if (command=="off") {
        // digitalWrite(led1,LOW);
        // digitalWrite(led2,LOW);
        digitalWrite(led3, LOW);
        return 0;
    }
    else {
        return -1;
    }
}

Another weird thing is, I keep getting getting updated message from Event Logs, meaning Particle.publish is working… but I can’t see functions and variables, it only says the Device is Offline

thank you for the help.

What device OS are you running?
With 0.8.0-rc.27 I've experienced difficulties with the otherwise preferable PietteTech_DHT library. Currently Adafruit_DHT should provide you with more relyable redings (although once this issue is solved - I'd go back to PietteTech_DHT)

That's not surprising, since for a Particle.publish() the device will be actively doing exactly that in your code, but for Particle.function() or Particle.variable() requests it needs to be actively listening to the cloud which can be prevented by your code while servicing other things (e.g. long lasting sensor readings - possible issue above) and not paying attention to the request.
As a workaround you can try SYSTEM_THREAD(ENABLED).

1 Like

Greetings,

Thank you, I am adding the SYSTEM_THREAD(ENABLED) now, and let me get back again if something improved. also I am using the latest version v0.8.0-rc.27

2 Likes

Greetings,

After more than 12 hours after adding SYSTEM_THREAD(ENABLED) the argons did not disconnect, and I can select and call functions from console very well. thank you for the suggestion.

1 Like

When the mere addition of SYSTEM_THREAD(ENABLED) solves the problem, you should still try to locate the blocking sections in your code and “repair” them.
SYSTEM_THREAD(ENABLED) acts like a painkiller but doesn’t actually cure your disease :wink:

3 Likes

Greetings,

going back again to this topic, the problem still persisted, randomly the device becomes unreachable. I tried fresh project, changing different library to Adafruit_DHT for getting temp for DHT11, but now I get 0 temperature/humidity.

Hey hokutosei,

That is rather unusual. If you don’t mind, would you mind sharing the device IDs with me, either here or in direct messages? I’d like to perform some more investigations on your devices on our end to see if anything sticks out to us.

Thanks!