Electron Particle keeps flashing green


#1

I have been having issues with my electron board. It breathes cyan for few minutes and then loose connection(start flashing green) for like a minute or two. This cycle goes on continuously. I have noticed the same pattern when I upload Electron-Server TCP communication program. Currently, In the code, I have a simple program that communicates with the server through UDP. See the code below.The program works fine ,but after almost every success cycle, it gets interrupted with connection loss…What am I doing wrong or is this common cell network issue? I am using Particle original sim card.

const size_t UDP_BUFFER_SIZE = 513;
const int REMOTE_UDP_PORT = 8081;
const IPAddress REMOTE_UDP_ADDR = IPAddress(xx, xxx, xxx, xxx);
const int LOCAL_UDP_PORT = 8888;
UDP Udp;

void setup() {
  Serial.begin(4800);
  delay(1000);
  Udp.begin(LOCAL_UDP_PORT);
}

void loop() {
  char buffer[] = "electronId";
  if (Udp.sendPacket(buffer, sizeof(buffer), REMOTE_UDP_ADDR, REMOTE_UDP_PORT) < 0) {
    Serial.println("error sending packet");
  }
  delay(1000);

  char message[128];
  int rxError = 0;

  int count = Udp.receivePacket((byte*)message, 127);
  if (count >= 0 && count < 128) {
    message[count] = 0;
    rxError = 0;
  } 
  else if (count < -1) {
    rxError = count;
    Udp.begin(LOCAL_UDP_PORT);
  }

  if (!rxError) {
    Serial.println(message);
        
    char messageReceived[] = "Verified";
    if (Udp.sendPacket(messageReceived, sizeof(messageReceived), REMOTE_UDP_ADDR, REMOTE_UDP_PORT) < 0) {
      Serial.println("error sending Message packet");
    }
    delay(3000)
  }
}

#2

Without diving too deep in your code, I guess you are running out of sockets since you are repeatedly calling Udp.begin() but never seem to release the socket with UDP.stop()

Before you (re)open a new connection you should make sure you are not still hogging another.


#3

Thank you for the response @ScruffR Are you talking about the Udp.begin under else if ? If that one, I should mention that is new, I added it recently, the issue has been there even before that change. Also on my other TCP client/server program , I do call client.stop at the end of each request/response cycle, but I experience the same issue. Which leads me to think might be an issue with cell network?


#4

maybe try a flash of fresh set of firmware & tinker.


#5

Even with the new firmware , still the same issue