DFROBOT SIM7000 Shield Guide

For those who have purchased a DFROBOT SIM7000 and was unable to get it working with the supplied library, I will present to you a guide in how I rectified the issue.

Firstly, I would like to thank the creator of this library BOTLETICS.

The Wiring
The square antenna is plugged into the GNSS socket.
The rectangle flat antenna is plugged into the GSM/LTE socket.
Set RX/TX switch to 7/8.
Insert Sim Card, mine works with a Telstra IOT simcard, I have not yet tested with a regular sim, will update when trialled.
Plug the shield into an Arduino UNO and power the UNO through the DC Barrel Jack with 9-12v as stated.

The Code

Download the library from the BOTLETICS GITHUB. This will be titled, ADAFRUIT_FONA_MASTER. Load up the example sketch titled SIM7XXX_LTE_DEMO. Change the following variables.

#define FONA_PWRKEY 12
#define FONA_TX 8
#define FONA_RX 7

If this is the first time starting the unit, leave the following code.

fonaSS.begin(115200);

The program will then set the baud to 9600, the SIM7000E remembers the baud.

Depending on your simcard, modify uncomment/comment the following code. In this example, I am using a telstra IOT simcard.

  //fona.setNetworkSettings(F("your APN"), F("your username"), F("your password"));
  //fona.setNetworkSettings(F("m2m.com.attz")); // For AT&T IoT SIM card
  fona.setNetworkSettings(F("telstra.internet")); // For Telstra (Australia) SIM card - CAT-M1 (Band 28)
  //fona.setNetworkSettings(F("hologram")); // For Hologram SIM card

Upload sketch to Arduino Uno, and open serial port at 9600 baud.

To configure HTTP, I had to add some additional code into the ADAFRUIT_FONA.CPP library to designate a bearer. Additionally, to ensure reliability, I added lines to close the bearer.

boolean Adafruit_FONA::postData(const char *request_type, const char *URL, const char *body, const char *token, uint32_t bodylen) {
  // NOTE: Need to open socket/enable GPRS before using this function
  // char auxStr[64];

  // Make sure HTTP service is terminated so initialization will run
  sendCheckReply(F("AT+HTTPTERM"), ok_reply, 10000);
  
  sendCheckReply(F("AT+CIPSHUT"), ok_reply, 10000);
  
  sendCheckReply(F("AT+SAPBR=3,1,\"APN\",\"telstra.internet\""), ok_reply, 10000);
  
  sendCheckReply(F("AT+SAPBR=1,1"), ok_reply, 10000);
  
  getReply(F("AT+SAPBR=2,1"));
  
  // Initialize HTTP service
  if (! sendCheckReply(F("AT+HTTPINIT"), ok_reply, 10000))
    return false;

  // Set HTTP parameters
  if (! sendCheckReply(F("AT+HTTPPARA=\"CID\",1"), ok_reply, 10000))
    return false;

  // Specify URL
  char urlBuff[strlen(URL) + 22];

  sprintf(urlBuff, "AT+HTTPPARA=\"URL\",\"%s\"", URL);

  if (! sendCheckReply(urlBuff, ok_reply, 10000))
    return false;

  // Perform request based on specified request Type
  if (strlen(body) > 0) bodylen = strlen(body);

  if (request_type == "GET") {
  	if (! sendCheckReply(F("AT+HTTPACTION=0"), ok_reply, 10000))
    	return false;
  }
  else if (request_type == "POST" && bodylen > 0 ) { // POST with content body
  	if (! sendCheckReply(F("AT+HTTPPARA=\"CONTENT\",\"application/x-www-form-urlencoded\""), ok_reply, 10000))
    	return false;

    if (strlen(token) > 0) {
      char tokenStr[strlen(token) + 55];

	  	sprintf(tokenStr, "AT+HTTPPARA=\"USERDATA\",\"Authorization: Bearer %s\"", token);

	  	if (! sendCheckReply(tokenStr, ok_reply, 10000))
	  		return false;
	  }

    char dataBuff[sizeof(bodylen) + 20];

		sprintf(dataBuff, "AT+HTTPDATA=%d,10000", bodylen);
		if (! sendCheckReply(dataBuff, "DOWNLOAD", 10000))
	    return false;

    delay(100); // Needed for fast baud rates (ex: 115200 baud with SAMD21 hardware serial)

		if (! sendCheckReply(body, ok_reply, 10000))
	    return false;

  	if (! sendCheckReply(F("AT+HTTPACTION=1"), ok_reply, 10000))
    	return false;
  }
  else if (request_type == "POST" && bodylen == 0) { // POST with query parameters
  	if (! sendCheckReply(F("AT+HTTPACTION=1"), ok_reply, 10000))
    	return false;
  }
  else if (request_type == "HEAD") {
  	if (! sendCheckReply(F("AT+HTTPACTION=2"), ok_reply, 10000))
    	return false;
  }

  // Parse response status and size
  uint16_t status, datalen;
  readline(10000);
  if (! parseReply(F("+HTTPACTION:"), &status, ',', 1))
    return false;
  if (! parseReply(F("+HTTPACTION:"), &datalen, ',', 2))
    return false;

  DEBUG_PRINT("HTTP status: "); DEBUG_PRINTLN(status);
  DEBUG_PRINT("Data length: "); DEBUG_PRINTLN(datalen);

  if (status != 200) {
	  getReply(F("AT+SAPBR=0,1"));
	  getReply(F("AT+HTTPTERM"));
	  return false;
  }

  getReply(F("AT+HTTPREAD"));

  readline(10000);
  DEBUG_PRINT("\t<--- "); DEBUG_PRINTLN(replybuffer); // Print out server reply

  // Terminate HTTP service
  sendCheckReply(F("AT+HTTPTERM"), ok_reply, 10000);
  
  getReply(F("AT+SAPBR=0,1"));

  return true;
}

Any problems, I will try my best to rectify.

Personally, I downloaded AT COMMAND TESTER:
https://m2msupport.net/m2msupport/download-at-command-tester-for-simcom-modules/
Installed the drivers from the BOTLETICS GITHUB, connected to my PC with a micro-usb whilst the unit was powered from an Arduino with a basic sketch like:

void setup() {
  pinMode(12,OUTPUT);
  digitalWrite(12,HIGH);
}

void loop() {
  delay(1000);
}

And programmed via Command Tester. The tester was extremely useful in determining what AT commands needed to be sent and when, and to initialize the AT+COPS? as some units did not automatically register to the network.

4 Likes

Hey Luke,

Thanks for providing all the intel on how to get it up and running! We have had a few customers working with these and running into specific issues we weren’t able to remedy so hopefully this can help them get started with IoT devices!

If you find yourself doing any projects you’d like to give more insight into, don’t hesitate to share it with the wider community by going through the project sharing process on our site.

Any users who have a project uploaded receive a $50 store credit!

1 Like

Thanks for your reply Owen,

More than happy to help others who may be experiencing some issues.

Will certainly be uploading a project very soon, thanks. :slight_smile:

2 Likes

Thank you Luke, I can now get the SIM7000 module started. I can retrieve information like voltage but unfortunately have not been able to retrieve the SIM card info or connect to the network. I have tried two cards, one Aldi (runs on Telstra network) and a Telstra SIM card. Neither are IOT cards. I will hunt if I can easily get an IOT card. If you, or anyone else, have any tips in getting a standard card running I would appreciate them.
My system is fairly basic, all I want to use is the SMS function. I have a genset, crossover switch, pump and valves that I use for my bush fire response plan. I wanted a reliable way to access the system, I chose SMS. Ran fine for a number of years before the closure of the 3G network.
Thanks for your help, I now feel that I may get it running again.

Hey Warren,

I was unable to get the unit working with SMS using a normal sim card, iv’e read they do not work with normal sim cards but it seems like something to do with PDP contexts. If you are able to get yourself a hologram simcard or a telstra IOT simcard that would be fantastic. You can use a service like pushing box API for free.
https://www.pushingbox.com/

Using an IOT Simcard you can make a HTTP Get request to a specific URL that is given to you by pushingbox, this will then send an e-mail to a designated e-mail address much like an SMS however much less expensive. Depending on your mobile or the receivers, you can change the alerts from e-mail addresses to be much more evident(louder ringtone sound, change notification colour etc.) This is the function I use to call the HTTP function in the Adafruit library.

//***********FUNCTIONS***************//

//HTTP GET REQUEST FUNCTION
void httpGET() {
  char URL[150];
  fona.setNetworkSettings(F("telstra.internet")); //change this if using hologram
  sprintf(URL, "http://pushingbox.com/yourdeviceid.....");
  fona.postData("GET", URL);
}

The library has had some slight modifications under the ::postdata function to add bearer and delays.

boolean Adafruit_FONA::postData(const char *request_type, const char *URL, const char *body, const char *token, uint32_t bodylen) {
  // NOTE: Need to open socket/enable GPRS before using this function
  // char auxStr[64];

  // Make sure HTTP service is terminated so initialization will run
  sendCheckReply(F("AT+HTTPTERM"), ok_reply, 10000);
  
  sendCheckReply(F("AT+CIPSHUT"), ok_reply, 10000);
  
  sendCheckReply(F("AT+SAPBR=3,1,\"APN\",\"telstra.internet\""), ok_reply, 10000);
  
  delay(5000); //This is a wait time to ensure the bearer receives an IP address
  
  sendCheckReply(F("AT+SAPBR=1,1"), ok_reply, 10000);
  
  getReply(F("AT+SAPBR=2,1"));
  
  // Initialize HTTP service
  if (! sendCheckReply(F("AT+HTTPINIT"), ok_reply, 10000))
    return false;

  // Set HTTP parameters
  if (! sendCheckReply(F("AT+HTTPPARA=\"CID\",1"), ok_reply, 10000))
    return false;

  // Specify URL
  char urlBuff[strlen(URL) + 22];

  sprintf(urlBuff, "AT+HTTPPARA=\"URL\",\"%s\"", URL);

  if (! sendCheckReply(urlBuff, ok_reply, 10000))
    return false;

  // Perform request based on specified request Type
  if (strlen(body) > 0) bodylen = strlen(body);

  if (request_type == "GET") {
  	if (! sendCheckReply(F("AT+HTTPACTION=0"), ok_reply, 10000))
    	return false;
  }
  else if (request_type == "POST" && bodylen > 0 ) { // POST with content body
  	if (! sendCheckReply(F("AT+HTTPPARA=\"CONTENT\",\"application/x-www-form-urlencoded\""), ok_reply, 10000))
    	return false;

    if (strlen(token) > 0) {
      char tokenStr[strlen(token) + 55];

	  	sprintf(tokenStr, "AT+HTTPPARA=\"USERDATA\",\"Authorization: Bearer %s\"", token);

	  	if (! sendCheckReply(tokenStr, ok_reply, 10000))
	  		return false;
	  }

    char dataBuff[sizeof(bodylen) + 20];

		sprintf(dataBuff, "AT+HTTPDATA=%d,10000", bodylen);
		if (! sendCheckReply(dataBuff, "DOWNLOAD", 10000))
	    return false;

    delay(100); // Needed for fast baud rates (ex: 115200 baud with SAMD21 hardware serial)

		if (! sendCheckReply(body, ok_reply, 10000))
	    return false;

  	if (! sendCheckReply(F("AT+HTTPACTION=1"), ok_reply, 10000))
    	return false;
  }
  else if (request_type == "POST" && bodylen == 0) { // POST with query parameters
  	if (! sendCheckReply(F("AT+HTTPACTION=1"), ok_reply, 10000))
    	return false;
  }
  else if (request_type == "HEAD") {
  	if (! sendCheckReply(F("AT+HTTPACTION=2"), ok_reply, 10000))
    	return false;
  }

  // Parse response status and size
  uint16_t status, datalen;
  readline(10000);
  if (! parseReply(F("+HTTPACTION:"), &status, ',', 1))
    return false;
  if (! parseReply(F("+HTTPACTION:"), &datalen, ',', 2))
    return false;

  DEBUG_PRINT("HTTP status: "); DEBUG_PRINTLN(status);
  DEBUG_PRINT("Data length: "); DEBUG_PRINTLN(datalen);

  if (status != 200) {
	  getReply(F("AT+SAPBR=0,1"));
	  getReply(F("AT+HTTPTERM"));
	  return false;
  }

  getReply(F("AT+HTTPREAD"));

  readline(10000);
  DEBUG_PRINT("\t<--- "); DEBUG_PRINTLN(replybuffer); // Print out server reply

  // Terminate HTTP service
  sendCheckReply(F("AT+HTTPTERM"), ok_reply, 10000);
  
  getReply(F("AT+SAPBR=0,1"));

  return true;
}
1 Like

Excellent Luke
I did get a IOT sim card from Telstra (It was a struggle, “what is an IOT sim card”) but eventually they figured it out, an MTM card. I have not had much time but I did install the card and I can now connect. I did try an SMS but no luck, I will try the push service when I get time and report back.
You have been a great help.

2 Likes

Hi Warren and Luke and all!
I’m from TelstraDev, Telstra’s Developer portal for all things API and IoT

I’ve actually used an Arduino device on NB-IoT to send and receive alerts with SMS. But I didn’t use the IoT hardware and IoT SIM to send the SMS, rather had the Arduino subscribe to an IoT broker via NB-IoT that ran in a node-red instance that used Telstra’s Messaging API to send and receive the text messages.

There’s an open source GitHub repo and video workshop of the solution if you are interested:

It’s definitely not easy enough to get a hold of IoT SIM cards, unfortunately! And I find that the retail stores don’t always know where to send you. The best bet is from this link: https://www.telstra.com.au/small-business/internet-of-things/data-sim-plans#non-shared
But it’s something Telstra is working on!

3 Likes

Hey Michelle,

Thanks for chiming in on this one! I’m just starting to have a read of those links and they look super helpful. Using the messaging API seems like a great alternative, I’m definitely going to have to take a look into this one myself.

The environment sensor is a classic IoT utilisation! I’m keen to see how other people will be able to use this on other projects.

1 Like

Hi all,

I have actually managed to get this shield working with a normal SIM card.

I simply had to add the following line at the end of setup

fona.setPreferredLTEMode(1);

and now sms and https data are working with a regular sim card.

Hopefully this will help someone.

2 Likes

Thanks for the feedback and additional input to the other posters. I had been inactive on this project for a while but am now starting to integrate the IOT aspects into our water samplers (we were just traditionally using external EEPROM data storage and a Electron Desktop App with serial to retrieve and graph the results). Due to memory limitation, I ended up discarding the Adafruit library and created some functions with bool controllers to do what I wanted using the currentMillis method to avoid program blocks with the original library, will release soon aswell.

I had spent about a week trying to use the SIM7000E with MQTT but was not able to get it working, it was a while back and forgot which command was giving an ERROR but I will be trying again in the very near future to update. I remember updating the firmware but to no avail.

Also interested to try out regular sim cards as I have been burning through data in the testing phase on the IOT sim which can prove costly if the appropriate plan isn’t taken up initially.

About to release 10+ of these into the wild, I now know how it feels for a mother to watch her first-born leave the house to work elsewhere or to head to University.

2 Likes

Nice work Luke! Keep us posted :slight_smile:

Cheers mate,

Just tried a normal simcard, no problems thanks for the update.

1 Like

Had a bit of time to try and test MQTT again but fails on the AT+CNACT command. Did this happen to you?

+CGATT: 1 //Attached to network
+CGDCONT: 1,"IP","telstra.internet","0.0.0.0",0,0,0,0
+CGPADDR: 1,10.94.xxx.xxx  //IP address
+SAPBR: CONTYPE: GPRS, APN: testra.internet, USER:, PWD
+CNACT: 0,"0.0.0.0"
+CNACT=1,1: OK --> +APP PDP: DEACTIVE
+CNACT=1,"telstra.internet": OK --> +APP PDP: DEACTIVE
+CNACT=2,"telstra.internet": OK 
+CNACT?: 0,"0.0.0.0"
--> insert more variations, and unit restarts.

Also played around with COPS,CIPSHUT,CIPCLOSE, latest firmware, trialled 3 units, Telstra IOT simcard.

What my understanding is I am unable to connect to the app network because each time I try to enable, it returns that PDP is deactivated, although +CGPADDR shows an IP address?

1 Like

Ah yes… figured it out…

Ended up just changing the APN to telstra.wap

AT+CGATT=0 --> OK
AT+CGDCONT=1,"IP","telstra.wap","0.0.0.0",0,0,0,0
AT+CNACT=1,"telstra.wap" --> +APP PDP: ACTIVE
AT+CNACT: 1,"10.152.xx.xx"

AND THE GLORIOUS

AT+SMCONF="URL","test.mosquitto.org","1883" --> OK
AT+SMCONF="KEEPTIME",60 --> OK
AT+SMCONN --> OK

Does this open up a can of worms, thanks for bringing this post back up others.

1 Like

Awesome!

I did a bit of work on this too a little while ago, but using AT commands directly instead of the library. Just leaving a link to my post here in case it helps anyone out using one of these modules not on an Arduino shield.

1 Like

Hello Luke, I’ve been trying for a week to send http requests with this shield, but I failed to do so, I’m using it in my graduation project, is there anyway I can can talk to you so you can help me out?
Or anybody else here who was able to successfully use it.