Sending SMS from Particle Electron using AT Commands

1 Like

In Germany we have a company offering 100 mb free internet and accepting SMS and phonecalls. Absolutely free of charge! :wink:
The company is called netzclub. It is btw sending advertising over SMS… So you should not get confused when a Ring interrupt is triggered and a rubbish SMS was received… :smiley:

this is a really important file. it lists a function named SMS send, debug output for ATCMD test, RX/TX

But I have no idea if we could use them.. I'm learning c++ right now so I'm not 100% familiar how to access the public functions?

using the externname: electronMDM::getline or something similar? --> I want to listen to the output line for the CALLID

what about accessing the public functions from the Class MDMParser ?
smsSend is a public function here, as well as setDebug -> with 3 for ATCMD, test

EDIT:
I'm searching for something like that... my attempts to access the functions inside this file failed so far..

#include "mdm_hal.h"

maybe adding the stm32 library can help...?

figured out that it needs to be this format: CLASS.function();

Even if you do not use that, there is Congstar which offers a SIM with 100 MB for €2 per month. It works great with the Electron. And it should be able to send and receive SMS.

Hi guys,

thank you very much, that’s really awesome!
Did you try if sending SMS even works when the GSM module is online?

AFAIK GRPS blocks the sending/receiving of SMS, so the u-blox module must suspend the GPRS channel for a second to send SMS,…

anyway - I just integrated it into my firmware, we’ll see if it works :smile:

I have created a basic library for sending and receiving text messages using Cellular.command()
It is at https://github.com/robynjayqueerie/electron-atcommand-library

4 Likes

Hi,

I’m actually trying to use your library. I forked it to rename the electron-atcommand-library.h and .cpp to both uCommand.h and ....cpp as the import wasn’t working for the Particle IDE (same for the folder example which should be renamed examples), yet when trying to compile the sms.ino example, I’m getting this error message:

sms2.cpp:5:22: fatal error: uCommand.h: No such file or directory
 void loop();

Did the library actually worked out for yourself?

Where do you see electron-atcommand-library.h / .cpp in this repo?

How did you import the lib into your project?
Are you building with Build, Dev or CLI?

Hi ScruffR,

Nowhere right? This is why I forked the repo and edited the spark.json file to point to the uCommand.h and .cpp files actually in the repo.

I imported the library using Build.

You don’t need to fork the library, you can simply add them as tabs in the IDE. Click the little + icon in the top right corner, and then copy&paste the files in their respective tabs.

1 Like

Yes I did realize that later :sweat_smile: thanx for the tip anyway.
(edit)
Well, I just remembered why I thought I had to fork the library: Build wouldn’t import it at all, I was getting this error message, and followed ScruffR’s advice (in a sense), by making sure that the infos in the spark.json file were indeed matching the content of the firmware folder.
Then when I attempted to import it again in Build everything went smooth.

In that case your include needs to look like this

#include "uCommand/uCommand.h"

If you have the files as seperate tabs, you don’t need the subdirectory, since all files live on the same level. But imported libraries live in their own subdirectory.

Yes, I did import the library via the Contribute Library option in Build. Thanks for the uCommand/ part, I had no idea about this but I guess this will save me time in the future...

Anyways, I tried to follow your advice

Unfortunately, same issue at the compile step :disappointed_relieved:
Here is the code:

/*
Basics of the SMS messaging system
*/
#include "ucCommand/uCommand.h"

STARTUP(cellular_credentials_set("orange", "", "", NULL));

uCommand uCmd;

void setup()
{
char res;
int atResult;
	//Cellular.off();
	delay(2000);
	Serial.println("Entering sms setup");
	pinMode(B0,OUTPUT);
	digitalWrite(B0, HIGH);	// turn power on
	uCmd.setDebug(false);
	// set up text mode for the sms
	atResult = uCmd.setSMSMode(1);
	if(atResult == RESP_OK){
		Serial.println("Text mode setup was OK");
	}
	else{
		Serial.println("Did not set up text mode");
	}
	delay(1000);

}


void loop()
{
int val,ret,res;
char c,i,str[80];

	while(1){
		Serial.println("Looking for an sms message");
		// read next available messages
		if(uCmd.checkMessages(10000) == RESP_OK){
			uCmd.smsPtr = uCmd.smsResults;
			for(i=0;i<uCmd.numMessages;i++){
				Serial.printlnf("message received %s",uCmd.smsPtr->sms);
				uCmd.smsPtr++;
			}
		}
		// return the last message back to the sender
		uCmd.smsPtr = uCmd.smsResults;
		if(uCmd.numMessages > 0){
			for(i=0;i<uCmd.numMessages-1;i++)uCmd.smsPtr++;
			sprintf(str, "Last message received: %s",uCmd.smsPtr->sms);
			if(uCmd.sendMessage(str,uCmd.smsPtr->phone,10000) == RESP_OK)
				Serial.println("Message sent successfully");
			else
				Serial.println("Message failed to send");
		}
		// delete all the messages
		uCmd.smsPtr = uCmd.smsResults;
		for(i=0;i<uCmd.numMessages;i++){
			if(uCmd.deleteMessage(uCmd.smsPtr->mess,10000) == RESP_OK){
				Serial.println("message deleted successfully");
			}
			else Serial.println("could not delete message");
			uCmd.smsPtr++;
		}
		delay(20000);
	}
}

Now here is the error message I'm receiving:

sms2.cpp:5:32: fatal error: ucCommand/uCommand.h: No such file or directory
 void loop();
compilation terminated.
make[1]: *** [../build/target/user/platform-10sms2.o] Error 1
make: *** [user] Error 2

I checked in the Build > Library > Private library, "uCommand.h" with capital "C".
I correctly :star: the Electron too in Build > Devices...

Try double checking your the exact spelling (before posting) :wink:

The error message is quite explicit about the problem :sunglasses:

2 Likes

Oh my gosh… :cold_sweat:
Well. It worked fine when spelled correctly, obviously.

Ahem. :sweat_smile:

1 Like

Sorry I was not aware that there were postings about my at command library. @Manitoba and @ScruffR.
I am using the library successfully for sms receive and send. Don’t forget you can’t use it with the Particle SIM you have to use a 3rd party SIM with SMS capability. That is the only issue I have.
The example program should work straight out of the box with appropriate changes as you have made for the telco
I used the Particle CLI to compile it. Set up a folder and just put the .cpp, .h and the .ino file in that folder, directed CLI to it, selected an Electron device to compile for and it compiled.
I would be happy to help if there are still issues. I did try to extend the routines to do some other AT commands besides the SMS but have not finished those.
I did experience naming problems when I tried to add the library to the Particle build library, that was because I had worked with the names uCommand and the Particle people wanted them named according to the name of the repository, which is why I just stuck them on my Github page. Just renaming them in the JSON file does not really do anything.
Regards

3 Likes