Hi, I'm trying to use an Uno with a Soil Moisture Sensor to Upload the sensor data to Thingspeak via cellular. I've had successes with an ESP32 Board and using WiFi, but the application is going to be in an area with no WiFi so it has to be cellular. I've tried looking around for tutorials or documentation for the DFRobot SIM7600CE-T Shield but I'm pretty lost. Could someone please help me with an example code for connecting to the 4G-LTE Network?
thanks for the link,
in that code there is a section
#define DEBUG true
#define LTE_RESET_PIN 6
#define LTE_PWRKEY_PIN 5
#define LTE_FLIGHT_PIN 7`
the manufacturer's documentation doesnt provide any of this and this seems to be custom board.
This is my modified code based on what I understood from the schematics on the product page.
#include <SoftwareSerial.h>
#include <stdio.h>
#include <string.h>
// API Key for the Thingspeak Channel
String Apikey = "4BNJQCX065ROGD5C";
//Setup Code for the LTE Shield
#define DEBUG true
#define LTE_RESET_PIN 6
#define LTE_PWRKEY_PIN 12
#define LTE_FLIGHT_PIN 2
//#define Sensor_PIN A1 //Soil Moisture Sensor Pin
SoftwareSerial mySerial(8, 7);
// Constant Tested Values for the Sensor
const int dry = 410; // value for dry sensor
const int wet = 300; // value for wet sensor
// Variables for calculation
//--------Get Soil Moisture-------------
int sensorVal = analogRead(A1); //analogRead reads pin a0 to a5
int percentageHumidity = map(sensorVal, wet, dry, 100, 0);
void setup()
{
Serial.begin(115200);
//while (!SerialUSB)
{
; // wait for Arduino serial Monitor port to connect
}
mySerial.begin(115200);
// mySerial.begin(UART_BAUD, SERIAL_8N1, MODEM_RXD, MODEM_TXD);
pinMode(LTE_RESET_PIN, OUTPUT);
digitalWrite(LTE_RESET_PIN, LOW);
pinMode(LTE_PWRKEY_PIN, OUTPUT);
digitalWrite(LTE_RESET_PIN, LOW);
delay(100);
digitalWrite(LTE_PWRKEY_PIN, HIGH);
delay(2000);
digitalWrite(LTE_PWRKEY_PIN, LOW);
pinMode(LTE_FLIGHT_PIN, OUTPUT);
digitalWrite(LTE_FLIGHT_PIN, LOW);//Normal Mode
delay(5000);
/*ModuleState = moduleStateCheck();
if (ModuleState == false) //if it's off, turn on it.
{
digitalWrite(PWR_KEY, LOW);
delay(3000);
digitalWrite(PWR_KEY, HIGH);
delay(10000);
SerialUSB.println("Now turnning the SIM7600 on.");
}*/
sendData("AT+CCID", 3000, DEBUG);
sendData("AT+CREG?", 3000, DEBUG);
sendData("AT+CGATT=1", 1000, DEBUG);
sendData("AT+CGACT=1,1", 1000, DEBUG);
sendData("AT+CGDCONT=1,\"IP\",\"apn\"", 1000, DEBUG);
sendData("AT+CIPSTART=\"TCP\",\"ltedata.apn\",80", 2000, DEBUG);
Serial.println("4G HTTP Test Begin!");
/* dht.begin();
delay(1000);
*/
}
void loop()
{
Serial.print("Moisture % = ");
Serial.println(percentageHumidity);
delay(100);
//-----------HTTP---------------------
String http_str = "AT+HTTPPARA=\"URL\",\"https://api.thingspeak.com/update?api_key=" + Apikey + "&field1=" + percentageHumidity + /*"&field2=" + (String)h +*/ "\"\r\n";
Serial.println(http_str);
sendData("AT+HTTPINIT\r\n", 2000, DEBUG);
sendData(http_str, 2000, DEBUG);
sendData("AT+HTTPACTION=0\r\n", 3000, DEBUG);
sendData("AT+HTTPTERM\r\n", 3000, DEBUG);
delay(5000);
}
bool moduleStateCheck()
{
int i = 0;
bool moduleState = false;
for (i = 0; i < 5; i++)
{
String msg = String("");
msg = sendData("AT", 1000, DEBUG);
if (msg.indexOf("OK") >= 0)
{
Serial.println("SIM7600 Module had turned on.");
moduleState = true;
return moduleState;
}
delay(1000);
}
return moduleState;
}
String sendData(String command, const int timeout, boolean debug)
{
// mySerial.begin(115200);
String response = "";
mySerial.println(command);
long int time = millis();
while ( (time + timeout) > millis())
{
while (mySerial.available())
{
char c = mySerial.read();
response += c;
}
}
if (debug)
{
Serial.print(response);
}
return response;
}
I'm getting the sensor readout on the serial monitor but nothing gets sent to the thingspeak channel.
Could you see if you can point out any mistakes I might have made?
I'm using an Arduino Uno with this Shield.
Product Page for the Shield
Looks like you have Rx and Tx the wrong way around. Also there are jumpers on the shield that need to be set to use pins 7/8 for serial... might want to check those as well.
Also... you are not waiting long enough after starting the modem before sending it commands. It takes 12-16 seconds according to the data sheet.
You also need to be looking for responses from the modem all the time... not just after sending it commands. It send status messages at start up. It send messages when it receives text messages, etc.
Does the modem start up? (lights come on?).
One more thing... there is no way you can run Software Serial at this speed.
Try 19200 to start with.
You can use the sketch below as a simple tester. It allows you to type AT commands in the serial monitor and see the responses. You will need to manually start the modem - hold down the BOOT button for a second then release.
#define RXPIN 7
#define TXPIN 8
#include <SoftwareSerial.h>
SoftwareSerial softSerial(RXPIN, TXPIN);
void setup()
{
Serial.begin (19200);
Serial.println("Starting...");
softSerial.begin (19200);
}
void loop()
{
while (Serial.available() > 0)
softSerial.write(Serial.read());
while (softSerial.available() > 0)
Serial.write(softSerial.read());
}
Output
Also - how are you powering everything?
Thanks for the reply. The RX and TX pins on the jumpers are labeled RX to D8, TX to D7. Would it be the other way around still?
The model starts up, I'm powering it with a 9V DC Adapter. The lights do come on and the blue led flashes 1/sec.
I'll Try your test sketch.
Thanks
You also need to be looking for responses from the modem all the time... not just after sending it commands. It send status messages at start up. It send messages when it receives text messages, etc.
Could you expand on this please?
I'll try with the slower speeds on SoftSerial
Yes in your program it should be Rx pin 7, Tx pin 8. The labelling on the modem is the opposite because Tx -> Rx and Rx -> Tx for serial communication.
Did you get the sketch I posted to work?
I uploaded the sketch you provided, powered the modem on, the light just stays on now instead of blinking. According to the product page, it's searching for network but it just stays on and doesnt go to blinking even after a few minutes.
Did you get anything in the serial monitor? (19200 baud)
With that code you may need to manually BOOT the modem to start it up. Pressed the BOOT button for about a second and release.
Yeah, I did that.
I only get this on the serial monitor
14:35:49.213 -> Starting...
Then nothing after I try the test "AT".
It takes about 16 seconds to fully start up.
Is the blue LED on?
Is the baud rate in the monitor set to 19200?
After the modem has fully started up try issuing the following AT command to temporarily set the baud rate for serial to match the test sketch.
AT+IPR=19200
The baud rate is correctly set, after waiting for 16ec to 1 minute I get this
Starting...
Then nothing if I issue any command. Only if I change the baud rate to 115200, I get
14:55:18.658 -> Starting...
14:55:41.173 -> AT
14:55:41.173 -> OK
Is there an AT command to force the modem to look for network or to set to a particular network?
How are you changing the baud rate?
in the sketch
If I issue AT+CSPN? it gives out my network name so It's recognizing what network the sim card is right?
115200 is too fast for Software Serial... you will not be able to communicate reliably... it may work occasionally but I recommend using 19200.
To do this the sketch AND the modem need to have matching baud rates.
If you have it running at 115200 then issue the following command to change the baud rate from the modem side.
AT+IPR=19200
Then change the baud rate in the sketch to match.
It's fine if it's unreliable at 115200, i just need it to work for now.
AT+CSPN?
15:07:56.527 -> +CSPN: "ROGERS",1
15:07:56.527 ->
15:07:56.527 -> OK
15:08:01.153 -> AT+CSQ
15:08:01.153 -> +CSQ: 99,99
15:08:01.153 ->
15:08:01.153 -> OK
15:08:11.461 -> AT+CREG?
15:08:11.461 -> +CR⸮G: 0,0
15:08:11.461 ->
15:08:11.461 -> OK
The modem itself is working it just wont connect to the network.
Well you could be missing half of the messages from the modem... but hey up to you.
I don't know why it is not connecting to the network... are you saying it was connecting before?
I understand what you're saying but I tried the slower BAUD rates and there's no response at all.
If I issue the command AT+COPS=?
which according to the manual is for network selection, it give out the following
15:10:04.215 -> AT+COPS=?
15:10:19.425 -> +COPS: (1,"ROGERS","⸮OGERS","302g20",7),(1,!Bell","BellB,"302610",7),(1,"MTS","LTS","2B,,,4)
If I need to select ROGERS, do you know what command I can issue?