Place a call - Electron

Hello,

i am trying to run the following function with a software timer or an interrupt without success:

void test() {
    const char* tel = "01234567890123";
    placeCall(tel);
}


int placeCall(const char* telNr)
{
  uint32_t duration = 30000;    
  int  ret;
    digitalWrite(led1,HIGH);
  if (!strlen(telNr)) return -1;

  if (!Cellular.ready())
  {
    Cellular.on();
    Cellular.connect();
    if (!waitFor(Cellular.ready, 5000))
    {
      Log.warn("no radio connection");
      Serial.println("no radio!");
      return -1;
    }
  }

  if ((ret = Cellular.command("ATD%s;\r\n", telNr)) == RESP_OK)
  {
    Log.info("Call pending");
    Serial.println("Call pending!");
    delay(duration);
    Cellular.command("AT+CHUP\r\n");
    Log.info("Hung up");
    Serial.println("Hung up!");
  }
  else
  {
    Log.warn("Call not possible (%d)", ret);
    Serial.println("Call not possible!");
  }
    digitalWrite(led1,LOW);
  return ret;
  
}

I now, there is a problem with using particle.publish with a timer but my function doesn´t include a publish…

In case of the timer, it ends with an SOS from the electron (13 times blinking)

in case of using an interrupt:

pinMode(D5, INPUT_PULLDOWN);
attachInterrupt(D5, test, RISING);

to run the “test” function, i get error “Call not possible” from placeCall()

Can anyone help me with my problem?
An idea to solve the problem may be very helpful!

Thanks a lot,

Stivi

There are other things than just Particle.publish() that should not be done in an ISR or a Software Timer callback.
One thing is using delay() which is part of that placeCall() function (which looks familiar :wink: )

If you want to place a call on a timer or interrupt, you should only set a flag in the respective handler and depending on that flag call the actuall function from loop()

Something like

volatile bool doCall = false;

void test() {
    doCall = true;
}

void loop() {
  if (doCall) {
    doCall = false;
    placeCall("01234567890123");  // you should actually use the international notation +10123456789
  }
}
2 Likes

@ScruffR

Thanks a lot! Now it´s working.

1 Like