[Solved]- Electron unable to handshake when plugged into breadboard

My specs: Electron 2G with Taoglas PCB antenna running firmware version 0.5.3

I am having a similar problem, however it does not appear to be only the breadboard that is giving me problems.

I have tried everything from a firmware perspective to remedy the problem (see the post I started on my saga yesterday) so I definitely have ruled out some sort of firmware or application related problem.

I am able to get my Electron to connect to the network occasionally. Sometimes it remains connected for hours upon hours on end, sometimes it can’t connect at all (mind you this is without moving the breadboard or the Electron… sometimes it just works for some reason).

I did some of the experimenting suggested above as far as trying to plug in different sides of the Electron to the breadboard to see if that influenced things. It would appear to me that when the A0 side of the Electron is plugged in, it is less likely to establish an internet connection, though it is not a 100% correlation (sometimes it still manages to connect).

I have also tried different antennas, which don’t seem to be any better or worse (still batting about 10% on my connection attempts whether using stock antenna or others I had lying around).

I tried the band select code that @BDub posted above, but I am unable to get any of the bands to work. I actually modified the code because it wasn’t working for me (the set bands portion specifically). I also changed the code so that you can attempt to connect or disconnect from Particle Cloud. Unfortunately, it appears that particle.connect() blocks the main application loop() from executing once it has been called, so this results in the Electron simply attempting to connect to the cloud forever (unsuccessfully). To get around this, I enabled system threading with SYSTEM_THREAD(ENABLED); so that the main loop() keeps executing while the Electron is trying to connect to the Particle Cloud. I enable a timer once the connection attempt begins. When the timer times out, I pass that info to the loop via timeoutFlag and attempt to abort the particle.connect() attempt with particle.disconnect() and Cellular.off(). This doesn’t work however… it would appear that once particle.connect() is called, it blocks all other core functions (i.e. particle.disconnect() ) from executing.

At the very least, this code will avoid others@noumanh having to flash a separate app to see if the new selected band works.

#include "application.h"

SYSTEM_THREAD(ENABLED);
SYSTEM_MODE(SEMI_AUTOMATIC);


// ALL_LEVEL, TRACE_LEVEL, DEBUG_LEVEL, INFO_LEVEL, WARN_LEVEL, ERROR_LEVEL, PANIC_LEVEL, NO_LOG_LEVEL
//SerialDebugOutput debugOutput(9600, ALL_LEVEL);



long timeout = 30000;  //Set connection timeout to 20 seconds
bool timeoutFlag = false;
bool connectFlag = false;
bool connectErrorFlag = false;

void setConnectFlags(){
  if(connectFlag==TRUE) timeoutFlag=TRUE;
}

Timer myTimer(timeout, setConnectFlags);

void waitForEnter() {
  WITH_LOCK(Serial){
    while (!Serial.available()) {
        Particle.process();
        Serial.print("Press ENTER\r"); // prints in place over and over
        delay(1000);
    }
    while (Serial.available()) Serial.read(); // Flush the input buffer
  }
}

void setup()
{
    Serial.begin(9600);
    waitForEnter();

    Serial.println("Running in SEMI_AUTOMATIC mode, cellular modem is OFF at boot, not connecting to the cloud."
                    "\r\nIf you select a band that never connects, press the RESET button and change the band.\r\n");

    Serial.println("Press a key to run a command:"
                "\r\n[O|o] to turn the cellular modem ON|OFF"
                "\r\n[g|s] get|set bands info"
                "\r\n[c|d] connect | disconnect from Particle Cloud");

    pinMode(D7, OUTPUT); //Use Electron on-board LED to indicate if connection attempt has failed
}

/* This function loops forever --------------------------------------------*/
void loop()
{
    if(connectErrorFlag == true){
      digitalWrite(D7, HIGH);
      delay(100);
      digitalWrite(D7, LOW);
      delay(100);
    }

    WITH_LOCK(Serial){

      if(timeoutFlag==TRUE){
        timeoutFlag = FALSE;
        myTimer.stop();
        if(Particle.connected()==FALSE){
          Serial.println("Connection attempt timed out!");
          connectErrorFlag = TRUE;
          Serial.println("Aborting connection attempt!");
          Particle.disconnect();
          Serial.println("Turning off the modem!");
          Cellular.off();
        }
        else{
          Serial.println("Successfully connected to Particle Cloud!");
          connectFlag = true;
        }
      }

      if (Serial.available() > 0)
      {
          char c = Serial.read();
          if (c == 'g') {
              CellularBand band_avail;
              if (Cellular.getBandAvailable(band_avail)) {
                  Serial.print("Available bands: ");
                  for (int x=0; x<band_avail.count; x++) {
                      Serial.printf("%d", band_avail.band[x]);
                      if (x+1<band_avail.count) Serial.printf(",");
                  }
                  Serial.println();
                  Serial.println(band_avail); // repeated to show printable
              }
              else {
                  Serial.printlnf("Bands available not retrieved from the modem!");
              }
              CellularBand band_sel;
              if (Cellular.getBandSelect(band_sel)) {
                  Serial.print("Selected bands: ");
                  for (int x=0; x<band_sel.count; x++) {
                      Serial.printf("%d", band_sel.band[x]);
                      if (x+1<band_sel.count) Serial.printf(",");
                  }
                  Serial.println();
                  Serial.println(band_sel); // repeated to show printable
              }
              else {
                  Serial.printlnf("Bands selected not retrieved from the modem!");
              }
          }
          else if (c == 's') {
              Serial.print("Enter one or more comma delimited bands in MHz (0 will set back to factory defaults,"
                          "\r\nPress ESC to cancel the operation): ");
              int done = false;
              String band = "";
              bool gotInput = FALSE;
              while (Serial.available()) Serial.read(); //Flush the serial buffer
              while (!done) {
                  if (Serial.available() > 0) {
                      gotInput = TRUE;
                      char c = Serial.read();
                      if (c == '\r') {
                          done = true;
                          Serial.println();
                      }
                      else if (c == 27) { // ESC
                          band = "";
                          done = true;
                          Serial.println("\r\nBand select cancelled!");
                      }
                      else {
                          band += c;
                          Serial.print(c); // echo
                      }
                  }
                  else if(gotInput==TRUE){
                    Serial.println("You must have finished entering your input...");
                    done = true;
                    delay(100);
                  }
                  Particle.process();
              }
              if(band != "") {
                  if (Cellular.setBandSelect(band.c_str())) {
                      Serial.printlnf("%s band(s) set! Value will be saved in NVM when powering off modem.", band.c_str());
                  }
                  else {
                      Serial.printlnf("%s band(s) not valid!", band.c_str());
                  }
              }
          }
          else if (c == '1') {
              Serial.println("Setting bands to 850");
              CellularBand band_sel;
              band_sel.band[0] = BAND_850;
              band_sel.count = 1;
              if (Cellular.setBandSelect(band_sel)) {
                  Serial.print(band_sel);
                  Serial.println(" band(s) set! Value will be saved in NVM when powering off modem.");
              }
              else {
                  Serial.print(band_sel);
                  Serial.println(" band(s) not valid!");
              }
          }
          else if (c == '2') {
              Serial.println("Setting bands to 1900");
              CellularBand band_sel;
              band_sel.band[0] = BAND_900;
              band_sel.count = 1;
              if (Cellular.setBandSelect(band_sel)) {
                  Serial.print(band_sel);
                  Serial.println(" band(s) set! Value will be saved in NVM when powering off modem.");
              }
              else {
                  Serial.print(band_sel);
                  Serial.println(" band(s) not valid!");
              }
          }
          else if (c == '3') {
              Serial.println("Setting bands to 850,1900");
              CellularBand band_sel;
              band_sel.band[0] = (MDM_Band)850;
              band_sel.band[1] = (MDM_Band)1800;
              band_sel.band[2] = (MDM_Band)3400; // forcing a bad value, still gets rejected
              band_sel.band[3] = BAND_2100;
              band_sel.count = 4;
              if (Cellular.setBandSelect(band_sel)) {
                  Serial.print(band_sel);
                  Serial.println(" band(s) set! Value will be saved in NVM when powering off modem.");
              }
              else {
                  Serial.print(band_sel);
                  Serial.println(" band(s) not valid!");
              }
          }
          else if (c == '4') {
              Serial.println("Setting bands to Factory Defaults!");
              CellularBand band_sel;
              band_sel.band[0] = BAND_DEFAULT;
              band_sel.count = 1;
              if (Cellular.setBandSelect(band_sel)) {
                  Serial.println("Factory defaults set! Value will be saved in NVM when powering off modem.");
              }
              else {
                  Serial.println("Factory defaults not set!");
              }
          }
          else if (c == 'O') {
              Serial.println("Turning on the modem!");
              Cellular.on();
          }
          else if (c == 'o') {
              Serial.println("Turning off the modem!");
              Cellular.off();
          }
          else if (c == 'c') {
              Serial.println("Trying to connect to the Particle Cloud!");
              connectFlag = true;
              connectErrorFlag = false;
              timeoutFlag = false;
              myTimer.start();
              Particle.connect();
          }
          else if (c == 'd') {
              Serial.println("Trying to disconnect to the Particle Cloud!");
              Particle.disconnect();
          }
          while (Serial.available()) Serial.read(); // Flush the input buffer
      }
    }


}
1 Like