Argon wifi connectivity unstable

I’m experiencing frequent unstable wifi (and therefore cloud) connectivity from my Argon.

Since few hours I ping every min the Argon and as a result initially there were offline periods between 1 and 12 mins now the situation is getting worse expanding to 7 hrs and online few minutes and again offline now.

The Argon (OS 2.3.0) is now in a remote location, connected via USB to the USB3 port of a wi-fi access point (for power) the signal of wifi should be very strong. Remotely rebooting the wi-fi access point does not change the situation.

The application loaded:

  • loop(): is empty

  • setup(): InfluxDB + BLE initialization and BLE.on();

  • Log initialization SerialLogHandler logHandler(LOG_LEVEL_INFO);

  • Cloud functions which trigger interaction to external sensors via BLE and storage of these information in InfluxDB (via INFLUXDB_RJL library). Few delay() function of fractions of seconds but should not impact as the Argon goes offline even without triggering the cloud function.

  • No sleep or wifi related code

Also the Argon is placed on a breadboard, and no component is connected to it (at the moment). Wifi antenna properly attached.

The last attempt to flash new firmware (in the short window while the argon was online) the Argon did not came back online yet.

Any idea of what could it be please?

KR,
dk

Make sure that USB3 on access point is able to provide at least (continuous) 500mA of current also the USB cable quality is really important.
Another thing, but this is just a theory, suggestion. I’m assuming that the access point and Argon are relatively close to each other and you also running BLE so all of them are on 2.4Ghz so maybe they are interfering each other. Also maybe the AP has some functionality to automatically switch between 2.4/5Ghz maybe it’s worth to try to disable this. And finally I’ll move Argon a little from AP connect to 5V 2A PS and tested

that could cause trouble:

USB 3.0, or SuperSpeed USB, uses broadband signaling that can interfere with cellular and 2.4GHz WIFI signaling

source

Something I would try is to place the photon further away from this USB3. Maybe a longer USB wire and some distance in between could help.

1 Like

@dreamER @gusgonnet appreciate both input.
The wired thing is that nothing particular has changed in the last 4 days when and in the last two it progressively deteriorated.
The plan is anyway to use a separate power supply and have it a bit more detached from the wifi. I hope this will improve the situation as need to have the system quite reliable.

What do you think if BLE.on(); is moved from the setup() and used in the cloud function when needed and than turn off again?

Maybe someone connected another device to the USB3 hub/ports?

that sounds like a good plan of action.

There is also Wi-Fi interference in channels that could come from another building/house.
source
I would try a Wi-Fi scanner and see if other routers in the area are creating trouble.

This is all building on top of the premise that the code you are running on your Argon has not changed lately, otherwise the first place to look will be in the firmware :wink:

Cheers!

on this one i’m sure is not the case.

I’m trying to flash the Argon but not able to catch a time where it is online and I have seen it’s only for less than a min. Is there any way to force to flash the tinker app from curl command (the idea would be to script it, that as soon at it appears it starts flashing)?

Edit: actually found via the web IDE is possible to compile and download the firmware binary and upload it directly: Cloud API reference | Reference Documentation | Particle

1 Like

Update: I gained control back to the Argon flashing the tinker app and the connectivity was quite stable for few hours.

I modified my app moving the BLE.on() and BLE.off() inside the cloud function. After flashing is not coming back online.

I start thinking there is something on the code that does not allow to boot properly the Argon probably as a variable initialization failure although the app compiles successfully.

Showing your code might be a good idea :wink:

1 Like

Sure, here the code:

#include "InfluxDB.h"

// MAC addresses of sensors
char *DEVICES[] = {
     "AA:BB:CC:AA:BB:CC",
     "AA:BB:CC:AA:BB:CC"
     };

#define HISTORY_DELTA 7890000 // 3 months
#define maxCharacteristics 30

static int deviceCount = sizeof DEVICES / sizeof DEVICES[0];


// BLE
BleCharacteristic sensorData;
BleCharacteristic writeMode;
BleCharacteristic writeHistoryMode;
BleCharacteristic batteryData;
BleCharacteristic timeData;
BleCharacteristic historyData;

BlePeerDevice peer;

void onDataReceived(const uint8_t *data, size_t len, const BlePeerDevice &peer, void *context);
void onSensorDataReceived(const uint8_t *data, size_t len, const BlePeerDevice &peer, void *context);
void onWriteModeDataReceived(const uint8_t *data, size_t len, const BlePeerDevice &peer, void *context);
void onWriteHistoryModeDataReceived(const uint8_t *data, size_t len, const BlePeerDevice &peer, void *context);
void onBatteryDataReceived(const uint8_t *data, size_t len, const BlePeerDevice &peer, void *context);
void onTimeDataReceived(const uint8_t *data, size_t len, const BlePeerDevice &peer, void *context);
void onHistoryDataReceived(const uint8_t *data, size_t len, const BlePeerDevice &peer, void *context);

// Buffer for reading data values from sensor
byte char_data[32];

// Array to store historical data values from sensors and write to database in a second stage
byte history_data[10][32];

// Log handling
SerialLogHandler logHandler(LOG_LEVEL_INFO);

String str = "";

double temp_pub;
int moist_pub;
int lux_pub;
int soil_pub;
int batt_pub;

long int timestamp;

// InfluxDB credentials
InfluxDB idb = InfluxDB("user", "password");



void setup()
{
    Log.info("Argon start");

    sensorData.onDataReceived(onSensorDataReceived, NULL);
    writeMode.onDataReceived(onWriteModeDataReceived, NULL);
    writeHistoryMode.onDataReceived(onWriteHistoryModeDataReceived, NULL);
    batteryData.onDataReceived(onBatteryDataReceived, NULL);
    timeData.onDataReceived(onTimeDataReceived, NULL);
    historyData.onDataReceived(onHistoryDataReceived, NULL);
    
    Particle.variable("temp", temp_pub);
    Particle.variable("moist", moist_pub);
    Particle.variable("lux", lux_pub);
    Particle.variable("soil", soil_pub);
    Particle.variable("batt", batt_pub);
    
    Particle.function("refresh",refresh);
    Particle.function("update",update);
    
    // InfluxDB details
    idb.setDatabase("test");
    idb.setDeviceName("particle");
    idb.setDebug(true);
}


void loop()
{
    // Do nothing
}


void onWriteModeDataReceived(const uint8_t *data, size_t len, const BlePeerDevice &peer, void *context)
{
    uint8_t flags = data[0];
    //Log.info("Writemode Data: Length  %d ", len);
}

void onWriteHistoryModeDataReceived(const uint8_t *data, size_t len, const BlePeerDevice &peer, void *context)
{
    uint8_t flags = data[0];
    //Log.info("WriteHistorymode Data: Length  %d ", len);
}

void onSensorDataReceived(const uint8_t *data, size_t len, const BlePeerDevice &peer, void *context)
{
    uint8_t flags = data[0];
    //Log.info("Sensor Data: Length  %d ", len);
}

void onBatteryDataReceived(const uint8_t *data, size_t len, const BlePeerDevice &peer, void *context)
{
    uint8_t flags = data[0];
    //Log.info("Battery Data: Length  %d ", len);
}

void onTimeDataReceived(const uint8_t *data, size_t len, const BlePeerDevice &peer, void *context)
{
    uint8_t flags = data[0];
    //Log.info("Time Data: Length  %d ", len);
}

void onHistoryDataReceived(const uint8_t *data, size_t len, const BlePeerDevice &peer, void *context)
{
    uint8_t flags = data[0];
    //Log.info("History Data: Length  %d ", len);
}


int refresh(String command) {
    if (command=="reboot"){
        Particle.publish("REBOOT", "from command", PRIVATE);
        System.reset();
        return 0;
    }
    else {
        return -1;
    }
}


int update(String command) {
    if (command=="update"){
        Particle.publish("UPDATE", "from command", PRIVATE);
        readsensors();
        return 0;
    }
    else {
        return -1;
    }
}


void readsensors()
{    
    for (int i = 0; i < deviceCount; i++)
    {
        for (int a = 1; a < 4; a++)
        {       
            char *deviceMacAddress = DEVICES[i];
            
            Log.info(" [*] Connecting to sensor %s - Attempt: %d of 3", deviceMacAddress, attempt);
            
            BLE.on();
            
            peer = BLE.connect(BleAddress(deviceMacAddress));
            
            if (peer.connected())
            {
                // Successfull
				//[...]
				BLE.off()
            }
            else
            {
                Log.info("[FAIL] SENSOR READ: sensor not connected...");
                delay(1500);
            }
        }
    }
}
1 Like

When I run your code (without the influx stuff) I still have full connection - except during the period while readsensors() is running as the could connection is only serviced sporadically.

That’s why you may also get a timeout notice when calling update, as this function may run too long before returning the result.

BTW, if you should happen to lose cloud connection with your device, you don’t need to reflash Tinker, you can just use Safe Mode.