Photon with intermittent connection


I’m working with Grove - Multichannel Gas Sensor using Photon particle. I am using the code below. The system works intermittently ie come online and go offline in periods of approximately 20 seconds. Due to this failure, the readings are never totaly complete. Some gas readings are not refreshed. In addition, because of the intermittent connection, it is difficult to redo the flash when necessary. It seems to be a bug in the code. I have already tested with 3 different units in two environments with different internet connections. The behavior is always the same. Some expert could check this code please …

Thanks for any help,


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

       // This #include statement was automatically added by the Particle IDE.
       #include "MutichannelGasSensor.h"
       // Read Data from Grove - Multichannel Gas Sensor
       #include <Wire.h>
       #include "MutichannelGasSensor.h"

       char eventinfo[64];
       char auth[] = "";
       unsigned int ms;
       int publishdelay = 60 * 1000;
       // Publish CO, Humidity, Dew Point
       void PublishMutichannelGasSensorInfo(){
       float c = gas.measure_CO();
       float d = gas.measure_H2();
       float e = gas.measure_NH3();
       float f = gas.measure_NO2();
       float g = gas.measure_C3H8();
       float h = gas.measure_C4H10();
       float i = gas.measure_CH4();
       float j = gas.measure_C2H5OH();
     Blynk.virtualWrite(V11, c);
     Blynk.virtualWrite(V12, d);
     Blynk.virtualWrite(V13, e);
     Blynk.virtualWrite(V14, f);
     Blynk.virtualWrite(V15, g);
     Blynk.virtualWrite(V16, h);
     Blynk.virtualWrite(V17, i);
     Blynk.virtualWrite(V18, j);
       // Publush event
       void Publish(char* szEventInfo){
       Spark.publish("Gas Sensor", szEventInfo);

      void InitializeMutichannelGasSensor(){
      unsigned char id;

      void InitializeApplication(){
      pinMode(D7, OUTPUT);

      void setup() {
      Serial.println("Initializing sensors...");

      void loop() {


@cesar, I assume you are aware of the Particle.publish() rate limit of one per second?

NOTE 1: Currently, a device can publish at rate of about 1 event/sec, with bursts of up to 4 allowed in 1 second. Back to back burst of 4 messages will take 4 seconds to recover.

I also notice you have 2 #include "MutichannelGasSensor.h" lines and you use the deprecated form Spark.publish() instead of the correct Particle.publish() version.

Which firmware version are you using?


The firmware version is 0.7.0
I corrected the fails that you have noticed. However, the device go offline and came online.
I tried several delays values, include no delay in void loop. The problem is the same…



This is the screen I see on the console.


Where is the code of that MultiChannelGasSensor library?
It’s very likely that this lib has some blocking parts that keep the controller from servicing the cloud in a timely manner.
You can add SYSTEM_THREAD(ENABLED) to reduce the risk of that happening, but that’s only a workaround. Better would be to make the library non-blocking.

BTW, you don’t need #include <Wire.h>

There are also some unresolved issues with 0.7.0 around stability of connection, you could try 0.6.3.


Look at your publish timestamps… 4 publishes in the same second. You should combine those into one publish so as not to exceed the publish rate limit as @peekay123 already mentioned. I’m not saying that’s the root of the problem, but it could be. It seems that there’s always a disconnect right after your publish sequence if you look at the console bar graph colors.


Here is how I put multiple data points in a single Particle Publish event.


Firstly thank you all for the suggestions. I’ll work with all of them. Great opportunity to learn.

Libraries can be found at;
The original ino code does not work with photon particle.

I’ve been using more than 4 publishes before with Photon and it always worked fine. However, I must take into account that some of the publishes did not come from sensor readings but calculations from the same readings. This can be significant, so that I will consider your suggestion and do some testing.

About The C-String I need to study a little



In that library are some goto START; ( :stuck_out_tongue_closed_eyes: ) instructions that may cause some connection issues.
You can add Particle.process() after the respective START labels to prevent that.

Which one - there are several examples?
For what reason, in what manner does it not work?


Though you can certainly use more than 4 publishes, you must still adhere to the rate limits. If you add a 1s delay between each of them, there’s no problem. You can also burst 4, and then not send any for the following 4 seconds, and all is well too. As long as you play by the rules, you should be fine.