Dear Arduino-fellows,
I would like to use the Arduino MKR NB 1500 along with a vodafone SIM card. It connects without any troubles to the vodafone network. However, it is not possible to connect to an http or mqtt server (please see code below).
I am using following this code:
// NB-IoT to Cloud v0.0
// 11.09.2019
// Uses some commands found at https://create.arduino.cc/projecthub/voske65/arduino-nb-iot-with-sim7020-and-t-mobile-027f8f
#include <SoftwareSerial.h>
#define TIMEOUT 200 // AT-command timeout in 100ms -> 200=20sec
#define COMMANDMAX 1024
const int SleepPin = 6;
const int PowerPin = 7;
char SimError[] = "SIM **Error ";
char SimTimeout[] = "SIM **Timeout ";
char MyIp[16];
char MyCicc[24];
int TimeOut = TIMEOUT;
SoftwareSerial mySerial(2,3);
char simresult[COMMANDMAX];
const char* NBstart[] = {
"ATZ",
"AT+CFUN=0",
"AT+CREG=2",
"AT*MCGDEFCONT=\"IP\",\"nb.inetd.gdsp\"",
"AT+CFUN=1",
"AT+COPS=1,2,\"26202\"", // sign up to Vodafone DE
"AT+CGCONTRDP",
"AT+CSQ",
"\0" // end script with 0x00
};
//const char* NBopensocket[] = {
// "AT+CSOC=1,2,1",
// "AT+CSOCON=0,15683,\"XXX\"", // T-Mobile Server socket 0
// "\0" // end script with 0x00
//};
const char* NBopensocket[] = {
"AT+CSOC=1,2,1",
"AT+CSOCON=0,15683,\"XXX\"", // T-Mobile Server socket 0
// "AT+CSOCON=0,80,\"https://XXX/addMessage\?text=XXX\"",
"\0" // end script with 0x00
};
const char* NBclosesocket[] = {
"AT+CSODIS=0",
"AT+CSOCL=0",
"AT+CGACT=0,1",
"\0" // end script with 0x00
};
const char* NBhelloworld[] = {
"AT+CSOSEND=0,0,\"Hello World!\"",
"\0" // end script with 0x00
};
int runscript(const char** scrpt) {
int t = 0;
int s = 1;
//Serial.println("\n** SimScript:");
while ( strlen( scrpt[t]) > 1) {
s = writecommand(scrpt[t]);
delay(1000);
if ( s == 1 ) ++t;
else break;
}
return (s);
}
int writecommand(const char* cmd) {
char c = 0;
int t = 0, n = 0;
simresult[0] = 0;
mySerial.flush();
mySerial.print(cmd); mySerial.print('\r'); mySerial.print('\n');
while ( n <= TIMEOUT ) {
if (mySerial.available()) {
c = mySerial.read();
simresult[t] = c; simresult[++t] = 0;
Serial.write(c);
}
else {
delay(100);
n++;
};
if ( (t > 3) && ( ( (simresult[t - 4] == 'O') && (simresult[t - 3] == 'K') && (simresult[t - 2] == '\r') && (simresult[t - 1] == '\n') ) || ( (simresult[t - 4] == 'O') && (simresult[t - 3] == 'R') && (simresult[t - 2] == '\r') && (simresult[t - 1] == '\n') ) ) ) break;
}
if (n >= TIMEOUT) {
Serial.println(SimTimeout);
return (-1);
}
else {
if ( (simresult[t - 4] == 'O') && (simresult[t - 3] == 'R') ) {
Serial.println(SimError);
return (0);
}
else return (1);
}
}
void setup()
{
mySerial.begin(19200);
Serial.begin(19200);
delay(1000);
runscript(NBstart);
delay(200);
runscript(NBopensocket);
}
void loop()
{
if (mySerial.available())
Serial.write(mySerial.read());
if (Serial.available())
mySerial.write(Serial.read());
//runscript(NBopensocket);
//delay(200);
runscript(NBhelloworld);
delay(200);
//runscript(NBclosesocket);
delay(500);
}
Do you have any idea to fix this?
This also didn't help me:
Thank you!