Electron blink fast Cyan in some operation

Hi,

I’m making monitoring system using Arduino nano combine with Electron.
Arduino nano will get the sensor data and send buffer in every 5secs or 10 secs to electron.
While Electron will readBuffer from Arduino and then send to the server.
I have timer which is set to turn system on 5 mins and turn system off 5 mins as cycles.

After all powered on, Arduino does its job and Electron can connect to internet normally (breath Cyan).
Sometimes Electron can send the data to server completely, but sometimes cannot.
50% of operation test fail because Electron blink fast Cyan even though at the starting point of that loop it can connect normally (breath Cyan). I don’t know what is this fast Cyan is, it seems to blink forever after it start. I check in the console and what I get is only “device came online”

On Device firmware 0.4.9. Here’s my code, I think there must be something missing but I’m not sure what it is. If anyone have any suggestion with the code or any tips, that would be much appreciate.

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

    // Constants
        const unsigned long SEND_INTERVAL_MS = 20000;
        const size_t READ_BUF_SIZE = 128;

        // Forward declarations
        void processBuffer();

        // Global variables
        int counter = 0;
        int led2 = D7;
        unsigned long lastSend = 0;

        char readBuf[READ_BUF_SIZE];
        size_t readBufOffset = 0;

        PMIC _pmic; // instantiate an object

        unsigned int nextTime = 0;    // Next time to contact the server
        HttpClient http;

        http_header_t headers[] = {
            { "Content-Type", "text/plain" },
            { "Accept" , "*/*"},
            { NULL, NULL } // NOTE: Always terminate headers will NULL
        };

        http_request_t request;
        http_response_t response;

        void setup() {
            _pmic.disableCharging();
        	Serial.begin(9600);
        	pinMode(led2, OUTPUT);

        	// Serial1 RX is connected to Arduino TX (1)
        	// Serial2 TX is connected to Arduino RX (0)
        	// Photon GND is connected to Arduino GND
        	Serial1.begin(9600);
        	delay(10000);
        	digitalWrite(led2, HIGH);
        }

        void loop() {
            while(Serial1.available()) {
                if (readBufOffset < READ_BUF_SIZE) {
                    char c = Serial1.read();
                    if (c != '\n') {
                        if (c != '\r') {
                            readBuf[readBufOffset++] = c;    
                        }
                    } else {
                        readBuf[readBufOffset] = 0;
                        processBuffer();
                        readBufOffset = 0;
                    }
                } else {
                    Serial.println("readBuf overflow, emptying buffer");
                    readBufOffset = 0;
                }
        	}
        }

        void processBuffer() {
            if (counter == 0 || counter < 3) {
                
                String data = String(readBuf);
                
                if (data.startsWith("|") && data.endsWith("|")) {
                    Spark.publish("log", "Data Sent.");
                    sendData(data);
        	        delay(1000);
                }
            }
            
            counter++;
            
            if (counter >= 3) {
                digitalWrite(led2, LOW);
            }
        }

        void sendData(String data) {
            request.hostname = "api.nahmdee.com";
            request.port = 80;
            request.path = "/api/iot/raw";
            request.body = data;
            
            http.post(request, response, headers);
        }

And I wonder another thing, is there a way to check how much data has been consumed after one operation? I would like to check how many data has been used in sending data to my server.

Thank you in advance.

Hello,

Let me ping someone that might be able to help, @rickkas7 are you able to assist?

Kyle