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.

1 Like

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.

1 Like

After add Particle.process() after goto START made enormous difference. Now the system go dow some times only, perhaps at a normal rate of Internet failure. I am still investigating…
I call the original code that is provided by Grove Multichannel Gas Sensor in:
The code in, require lib that never finish. For each lib required that I provide, other is requested…never finish

I am using only 4 publishes now. In fact, the difference is that; more than 4 is not published. However, this does not seem to affect the intermittent connection. This also doesn’t affect the Blynk mode.

I am still doing tests…


Acutally I said

So after the linea that read


If you add it after the goto START; line it won’t actually be executed, as the code flow is sent back to START: before it actually reaches the following line.


So we have a problem:
By the wrong way, adding Particle.process(): after goto START: works
By the correct way i.e., adding Particle.process(): after START: does not work

This is really confusing
I am doing some thing wrong?


That’s odd, but have you actually written a colon instead of semicolon after Particle.process()?

If you are working with Web IDE you could post a SHARE THIS REVISION link to see what you currently have.

I don’t know about Web IDE. Can I have other options?
Thanks for any help


If you don’t know Web IDE, you should try to find out.

Have a look here and test this slightly adapted version of your project


Unfortunately it did not work.
This the screen that I obtain with your code modified.

This is the screen that I obtain with the original code correct by the wrong way.

Try this

But of course, you need to re-insert your Blynk token here

const char auth[] = "yourTokenHere";   // insert your private token

If something still won’t work, it might be good to check the serial output of the project. That’s what it is for :wink:

1 Like


This is the result…

If I had one of these sensor I could test the library modifications I did, but theoretically they should work.

However, I’ve added some extra error-treatment to flush the Wire buffer in case of inconsistent data, so give this a try

1 Like