3rd party sim communication issue

I am trying to communicate with GSM modem of particle electron(3G) via serial terminal(Termite).I am getting “OK” for “AT” command. But for all other AT commands i am getting “CME Error : Operation not supported”.
I have used this sample code : https://1ot.mobi/blog/debugging-with-the-particle-electron.
This is happening for both 3rd party and particle sim.

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

1 Like

I believe there are two problems with that program. The default serial read timeout is 1 second, and it’s reading as many characters as can be read in 1 second, so your command is probably getting cut off. I changed the timeout to 10 seconds and changed readString to readStringUntil and it works for me.

// https://1ot.mobi/blog/debugging-with-the-particle-electron

#include "Particle.h"

SYSTEM_MODE(SEMI_AUTOMATIC);

int parseResponse(int type, const char* buf, int len, int* point);

const int AT_TIMEOUT = 30000;

void setup() {
    Serial.begin(9600);
    Serial.println("Starting cellular, waiting 10s.");
    Cellular.on();
    delay(10000);
    Serial.println("Cellular started. Ready to receive AT commands.");
    Serial.setTimeout(10000);
}

void loop() {

    if (Serial.available() > 0) {

        String input = Serial.readStringUntil('\r');

        Serial.println("Received input: "+input);

        Serial.println("--BEGIN RESPONSE--");
        int point;
        Cellular.command(parseResponse, &point, AT_TIMEOUT, input+"\r\n");
        Serial.println("--END RESPONSE--");
    }
}


int parseResponse(int type, const char* buf, int len, int* point) {

    char line[1024+64];
    strncpy(line, buf, len);
    line[len] = '\0';
    String line_as_string = String(line);
    Serial.println(line_as_string.trim());

    if (type == TYPE_ABORTED) {
        return RESP_ABORTED;
    }
    else if (type == TYPE_PROMPT) {
        return RESP_PROMPT;
    }
    else if (type == TYPE_ERROR) {
        return RESP_ERROR;
    }
    else if (type == TYPE_OK) {
        return RESP_OK;
    }
    else {
        return WAIT;
    }
}

1 Like

I uploaded your program to my electron board,but now the board is stuck into Listening mode.

Do you really mean listening mode, blinking dark blue? It will breathe dark blue when you run that program because cellular is on but not connected, that’s normal for the way it was originally written.

Just flash a regular program over it by USB or enter safe mode to revert it to normal behavior.

yes it was breathing dark blue. But i am still not getting proper response for AT commands.

“CME Error : Operation not supported” for all the AT commands listed in the link.I get “Ok” response only for AT

Not sure then. Since cellular is on but not connected there’s a limited number of commands that will work, but the general information ones like:

AT+CCID

should work. It there a reason you want to send raw commands like that anyway?

I am doing this check weather the board is working well with particle sim and 3rd party sim. Is there any better way to do it?

Yes, use the cloud debugging tool instead.

Make sure you unplug the USB power and battery when switching between the Particle SIM and a 3rd-party SIM card.

#include "cellular_hal.h"
#include "Particle.h"

#define MAX_PHONE_NUMBER 14
#define CTRL_Z 0x1A
#define TIMEOUT 10000

SYSTEM_MODE(AUTOMATIC);

STARTUP(cellular_credentials_set("airtelgprs.com","","", NULL));

int lowerLimit = 50;
boolean smsSend = false;
int led = D6;
int photoresistor = A0; 
int power = A5; 
int analogvalue; 

char PhoneNumber[MAX_PHONE_NUMBER] = "";

void setup()
{
    
    Serial.begin(9600);
    
    Cellular.on();
    Cellular.connect();
    
     Particle.keepAlive(120);

    
    pinMode(led,OUTPUT); // Our LED pin is output (lighting up the LED)
    pinMode(photoresistor,INPUT);  // Our photoresistor pin is input (reading the photoresistor)
    pinMode(power,OUTPUT); // The pin powering the photoresistor is output (sending out consistent power)// Next, write one pin of the photoresistor to be the maximum possible, so that we can use this for power.
    digitalWrite(power,HIGH);
    
}

void loop()
{
    analogvalue = analogRead(photoresistor);
    Serial.print("Sensor values:");
    Serial.print(analogvalue);
    Serial.print("\n");
    
        if(analogvalue < lowerLimit && analogvalue != 0){
        if(!smsSend){
			char szMessage[64];
			
			sprintf(szMessage, "It's too dark here (%d analogvalue)", analogvalue);
			
			sendMessage(szMessage);
            
            smsSend = true;
        }
    } 
    else{
        smsSend = false;
    }
}

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){
    char szCmd[64];
    
    sprintf(szCmd, "AT+CMGS=\"+%s\",145\r\n", PhoneNumber);
    
    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 Send");
    }
    else{
        Serial.println("+ERROR, error sending message");
    }
    
    return retVal;
}

I am trying to get sms when value of photoresistor is less than 50.But still i am getting “Operation not supported” .

@rickkas7 @krvarma Can you help me with this?

Issue is solved!

If you have any info on how you solved it, the community might benefit from it.

2 Likes

Mistake was from my end. Code works fine, i was entering + sign twice with country code in the phone number string and Send SMS function.