Hi all,
I’ve been unsuccessfully trying to send SMS with a third party SIM card recently, following different threads of the forum. Now I’m trying this one (albeit a bit modified as I don’t have a light sensor handy).
Now I’m struggling with the connection to the network. My Electron will breathe white, then blink green. Sometimes, it will just keep blinking green, and after a few minutes, reset back to breathing white and start back the connection attempt. I think that there is an internal timer, some kind of watchdog, that resets the whole thing if the connection is not established after a while, am I right?
Some other times though, the Electron will blink cyan (with some red blinking sequences here and there). I read here that this could mean that the device indeed did successfully connect to my carrier’s network, yet without being able to connect to the Particle Cloud.
Anyways, from there I encountered two scenarios:
- Breathing Cyan (only once). Hourray! But the problem was that my code wasn’t running actually, no LED blinking or SMS being sent.
- Back to the beginning and to the white breathing and so on.
- Once the Electron was breathing blue and then started everything again.
I verified the code with Build, then compiled and downloaded it.
I flashed it with particle flash --usb firmware.bin
after putting the Electron in DFU mode.
So I guess that as there might be many different issues here, my question would be: as the Electron won’t run my code unless it’s connected to the Particle Cloud, is there a way to prevent it from doing so? It would help me test the code quickier…
Here is the code just in case it itself would be the cause of this erratic behavior.
#define MAX_PHONE_NUMBER 14
#define CTRL_Z 0x1A
#define TIMEOUT 10000
#include "cellular_hal.h"
STARTUP(cellular_credentials_set("sl2sfr", "", "", NULL));
// Credential here are for RED by SFR network, here in France
char szPhoneNumber[MAX_PHONE_NUMBER] = "+???????????";
bool smsSend = false;
const int Sec = 1000;
const int Min = 60*Sec;
unsigned long Millis_Previous = 0;
unsigned long Millis_Interval = 1*Sec;
unsigned long Millis_Actual;
// bool de_lay;
const int LED = D0;
bool LED_State = 0;
const int LED_SMS = D2;
bool LED_SMS_State = 0;
int Timer_Value = 0;
char szMessage[64];
void setup() {
Serial.begin(9600);
// Spark.function("setmin", setLowerLimit); // unused particle function from the original code
}
void loop() {
LED_OnOff();
Timer();
sendMessage(szMessage);
delay(1000);
}
void LED_OnOff(){
Millis_Actual = millis();
if(Millis_Actual - Millis_Previous >= (Millis_Interval/2)){
Millis_Previous = Millis_Actual;
if(LED_State = false){
LED_State = true;
} else {
LED_State = false;
}
digitalWrite(LED, LED_State);
}
}
void Timer(){
Millis_Actual = millis();
if(Millis_Actual - Millis_Previous >= ((2*Min))){
Timer_Value = millis();
Millis_Previous = Millis_Actual;
sprintf(szMessage, "Timer value = (%.4i Timer_Value)", Timer_Value);
smsSend = true;
}
}
int callback(int type, const char* buf, int len, char* param){
Serial.print("Return: ");
Serial.write((const uint8_t*)buf, len);
Serial.println();
return WAIT;
}
int sendMessage(char* pMessage){
if(!smsSend) return EXIT_SUCCESS;
char szCmd[64];
sprintf(szCmd, "AT+CMGS=\"+%s\",145\r\n", szPhoneNumber);
Serial.print("Sending command ");
Serial.print(szCmd);
Serial.println();
char szReturn[32] = "";
Cellular.command(callback, szReturn, TIMEOUT, "AT+CMGF=1\r\n");
Cellular.command(callback, szReturn, TIMEOUT, szCmd);
Cellular.command(callback, szReturn, TIMEOUT, pMessage);
sprintf(szCmd, "%c", CTRL_Z);
int retVal = Cellular.command(callback, szReturn, TIMEOUT, szCmd);
if(RESP_OK == retVal){
Serial.println("+OK, Message Sent");
}
else{
Serial.println("+ERROR, error sending message");
}
return retVal;
smsSend = false;
}