-
-
Notifications
You must be signed in to change notification settings - Fork 26
Unable to connect AWS #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi @rreddys i have tested the aws connection following this guide https://create.arduino.cc/projecthub/Arduino_Genuino/securely-connecting-an-arduino-mkr-wifi-1010-to-aws-iot-core-a9f365?f=1 and seems works, have you follow all the steps here described? |
Closed due to lack of feedback, @rreddys please reopen the issue if you need |
@Rocketct I also have the issue reported by rreddys. I did follow the instructions on the link you provided but on the serial monitor I can only see "." when the board attempts to connect to the MQTT server at AWS. |
i had tested recently, and i was able to make it works fine, what is strange is the time:
this could be a problem, however during this phase the board make the handshake to open connect to the cloud and and allow you to sand data to the AWS, can i ask if you have another gsm or another baord to test it? which mobile operator are you using? |
Hi many thanks for your reply ,
Unfortunately I don’t have another board to test the code . My network provider is EE (ee.co.uk).
About the date I did noticed on the article (securely connecting MKR 1010 to AWS IoT Core) that apparently the time and day sometimes can be out of sync and is suggested to change the RTC of the modem via AT commands to the current time.
As you well pointed out my board seems to have this problem however I’m not sure how to do this . Have you ever have to change the RTC on your board ?
The commands mention on the discussion are :
AT+CCLK? To check the time
And
AT+CCLK=“yy/mm/dd,hh:mm:ss+TZ
Any ideas on how to do the above ? Maybe this will fix the problem
Regards
Ruben
…Sent from my iPhone
On 13 Mar 2020, at 13:00, Riccardo Rizzo <notifications@github.com> wrote:
i had tested recently, and i was able to make it works fine, what is strange is the time:
18:36:49.971 -> AT+CCLK?\
\
18:36:49.971 -> +CCLK: "04/01/01,01:22:02+00"
this could be a problem, however during this phase the board make the handshake to open connect to the cloud and and allow you to sand data to the AWS, can i ask if you have another gsm or another baord to test it? which mobile operator are you using?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
if have i'll share as soon i'll find it, the idea is to assign a new getTime function for bear ssl, using a time retrieved by a ntp server, i remember to have an example, other question:
|
here the example with the ntp server, i have keep the same name in this way you shall only copy and paste, to understand in my test this is the results:
here the code:
it should works the ntp server set by me, eventually try to find the best one for your region, let me know if works |
1. this is the first time you try to connect to AWS correct? before have you connected the board to other cloud(Arduino cloud included)
Yes, I have only attempted to connect to AWS.
2. are you using the same ECC slot you have locked while the ecc508 configuration phase, right?
Yes , as from the example I’m using slot “0” I also named my thing the same on both AWS and the CSR
|
yes i got it the, before to move thorught the RTC i suggest to change the time through AT+CCLK, you have to convert from unix time in the string suggested by the at command manual(there are a lot of algorithm) and after add to the code: MODEM.sendf("AT+CCLK=\"%s\"", String__format_request_time);
if (MODEM.waitForResponse(100, &response) != 1) {
return 0;
} As you have for sure seen, we don't have implemented the set time on the library. To manipulate the RTC you can use the RTCZero library. |
Hi Ricardo
I tried with thecae below but I get the same results, I managed to connect to my network and I can see the device login to AWS however on the MQTT process it hangs and only shows “…..”
I think I need to try to change the RTC but I can’t find an example on the net on how to use AT commands on Arduino … do you have a sample script ?
|
Hi Ruben, ok there is not an example because we not an example made properly to show how to use the at command, you ca use this https://github.com/arduino-libraries/MKRGSM/tree/master/examples/Tools/SerialGSMPassthrough to set the samd works in passtrhough mode and send single command to the module, this because we not support this feature, any damages made by this will not be refunded. |
@SkyFoxProjects i forgot to ask, are you using a battery pack and last version of the library(MKRGSM), right? if no you shall use them, are mandatory and the battery should be at least of 2500 mAh. Also if you don't bought recently (in last month), make the patch described here arduino-libraries/MKRGSM#66 (comment) |
mean while, the modified version to set the rtc in the SARA, please take a look on setModuleTime, in my case 'm following to use the ntp server, to get the correct unix time, but could help you to understand how to send something to the Sara from the main sketch and without the serial pass through sketch:
you can use directly the rtclib of adafruit, i take the code from there to parse the unix time in human readable one |
Hi Riccardo. I use you code below and it is now clear that the error is on the time… see the attached results of the serial monitor:
12:19:59.059 -> OK
12:19:59.059 -> You're connected to the cellular network
12:19:59.059 ->
12:19:59.059 -> AT+USOCR=17
12:19:59.059 -> +USOCR: 0
12:19:59.059 ->
12:19:59.059 -> OK
12:19:59.096 -> AT+USOLI=0,2390
12:19:59.096 -> OK
12:19:59.130 -> AT+USOST=0,"129.6.15.28",123,48,"E30006EC0000000000000000314E31340000000000000000000000000000000000000000000000000000000000000000"
12:19:59.130 -> +USOST: 0,48
12:19:59.130 ->
12:19:59.130 -> OK
12:20:00.123 -> Error
12:20:00.123 -> Error: time not configured
Ruben Riano
Managing Director
SkyFox Digital
m | +44 (0) 7513052354
e | ruben.riano@skyfoxdigital.com <mailto:ruben.riano@skyfoxdigital.com>
w | www.skyfoxdigital.com <http://www.skyfoxdigital.com>
On 16 Mar 2020, at 11:07, Riccardo Rizzo <notifications@github.com <mailto:notifications@github.com> > wrote:
#include <ArduinoBearSSL.h>
#include <ArduinoECCX08.h>
#include <ArduinoMqttClient.h>
#include <MKRGSM.h>
#include "arduino_secrets.h"
/////// Enter your sensitive data in arduino_secrets.h
const char pinnumber[] = SECRET_PINNUMBER;
const char gprs_apn[] = SECRET_GPRS_APN;
const char gprs_login[] = SECRET_GPRS_LOGIN;
const char gprs_password[] = SECRET_GPRS_PASSWORD;
const char broker[] = SECRET_BROKER;
const char* certificate = SECRET_CERTIFICATE;
GSM gsmAccess(true);
GPRS gprs;
GSMClient gsmClient; // Used for the TCP socket connection
BearSSLClient sslClient(gsmClient); // Used for SSL/TLS connection, integrates with ECC508
MqttClient mqttClient(sslClient);
unsigned int localPort = 2390; // local port to listen for UDP packets
IPAddress timeServer(129, 6, 15, 28); // time.nist.gov <http://time.nist.gov/> <http://time.nist.gov <http://time.nist.gov/> > NTP server
const int NTP_PACKET_SIZE = 48; // NTP time stamp is in the first 48 bytes of the message
byte packetBuffer[ NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing packets
GSMUDP Udp;
unsigned long lastMillis = 0;
void setup() {
Serial.begin(115200);
while (!Serial);
if (!ECCX08.begin()) {
Serial.println("No ECCX08 present!");
while (1);
}
// First connection here to allow upd transmssion and mdule time change,
// i change with a while required allow transmission
while (gsmAccess.status() != GSM_READY || gprs.status() != GPRS_READY) {
connectGSM();
}
Udp.begin(localPort);
// prattically this is what before had in the get time, the difference is the last code
// lines where is set the mdule time by using the AT+CLKC command
if (!setModuleTime()) {
Serial.println("Error: time not configured");
while (1);
}
Serial.println("time set done");
// Set a callback to get the current time
// used to validate the servers certificate
ArduinoBearSSL.onGetTime(getTime);
// Set the ECCX08 slot to use for the private key
// and the accompanying public certificate for it
sslClient.setEccSlot(0, certificate);
// Optional, set the client id used for MQTT,
// each device that is connected to the broker
// must have a unique client id. The MQTTClient will generate
// a client id for you based on the millis() value if not set
//
// mqttClient.setId("clientId");
// Set the message callback, this function is
// called when the MQTTClient receives a message
mqttClient.onMessage(onMessageReceived);
}
void loop() {
if (gsmAccess.status() != GSM_READY || gprs.status() != GPRS_READY) {
connectGSM();
}
if (!mqttClient.connected()) {
// MQTT client is disconnected, connect
connectMQTT();
}
// poll for new MQTT messages and send keep alives
mqttClient.poll();
// publish a message roughly every 5 seconds.
if (millis() - lastMillis > 5000) {
lastMillis = millis();
publishMessage();
}
}
unsigned long getTime() {
return gsmAccess.getTime();
}
void connectGSM() {
Serial.println("Attempting to connect to the cellular network");
while ((gsmAccess.begin(pinnumber) != GSM_READY) ||
(gprs.attachGPRS(gprs_apn, gprs_login, gprs_password) != GPRS_READY)) {
// failed, retry
Serial.print(".");
delay(1000);
}
Serial.println("You're connected to the cellular network");
Serial.println();
}
void connectMQTT() {
Serial.print("Attempting to MQTT broker: ");
Serial.print(broker);
Serial.println(" ");
while (!mqttClient.connect(broker, 8883)) {
// failed, retry
Serial.print(".");
delay(5000);
}
Serial.println();
Serial.println("You're connected to the MQTT broker");
Serial.println();
// subscribe to a topic
mqttClient.subscribe("arduino/incoming");
}
void publishMessage() {
Serial.println("Publishing message");
// send message, the Print interface can be used to set the message contents
mqttClient.beginMessage("arduino/outgoing");
mqttClient.print("hello ");
mqttClient.print(millis());
mqttClient.endMessage();
}
void onMessageReceived(int messageSize) {
// we received a message, print out the topic and contents
Serial.print("Received a message with topic '");
Serial.print(mqttClient.messageTopic());
Serial.print("', length ");
Serial.print(messageSize);
Serial.println(" bytes:");
// use the Stream interface to print the contents
while (mqttClient.available()) {
Serial.print((char)mqttClient.read());
}
Serial.println();
Serial.println();
}
unsigned long sendNTPpacket(IPAddress& address)
{
//Serial.println("1");
// set all bytes in the buffer to 0
memset(packetBuffer, 0, NTP_PACKET_SIZE);
// Initialize values needed to form NTP request
// (see URL above for details on the packets)
//Serial.println("2");
packetBuffer[0] = 0b11100011; // LI, Version, Mode
packetBuffer[1] = 0; // Stratum, or type of clock
packetBuffer[2] = 6; // Polling Interval
packetBuffer[3] = 0xEC; // Peer Clock Precision
// 8 bytes of zero for Root Delay & Root Dispersion
packetBuffer[12] = 49;
packetBuffer[13] = 0x4E;
packetBuffer[14] = 49;
packetBuffer[15] = 52;
//Serial.println("3");
// all NTP fields have been given values, now
// you can send a packet requesting a timestamp:
Udp.beginPacket(address, 123); //NTP requests are to port 123
//Serial.println("4");
Udp.write(packetBuffer, NTP_PACKET_SIZE);
//Serial.println("5");
Udp.endPacket();
//Serial.println("6");
}
int setModuleTime() {
sendNTPpacket(timeServer); // send an NTP packet to a time server
// wait to see if a reply is available
delay(1000);
if ( Udp.parsePacket() ) {
// We've received a packet, read the data from it
Udp.read(packetBuffer, NTP_PACKET_SIZE); // read the packet into the buffer
//the timestamp starts at byte 40 of the received packet and is four bytes,
// or two words, long. First, esxtract the two words:
unsigned long highWord = word(packetBuffer[40], packetBuffer[41]);
unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]);
// combine the four bytes (two words) into a long integer
// this is NTP time (seconds since Jan 1 1900):
unsigned long secsSince1900 = highWord << 16 | lowWord;
const unsigned long seventyYears = 2208988800UL;
// subtract seventy years:
unsigned long epoch = secsSince1900 - seventyYears - 946684800UL;
String hours = String((epoch % 86400L) / 3600);
if (((epoch % 86400L) / 3600) < 10 ) {
// In the first 10 minutes of each hour, we'll want a leading '0'
hours = "0" + hours;
}
String minutes = String((epoch % 3600) / 60);
if ( ((epoch % 3600) / 60) < 10 ) {
// In the first 10 seconds of each minute, we'll want a leading '0'
minutes = "0" + minutes;
}
String seconds = String(epoch % 60);
epoch /= 3600;
const uint8_t daysInMonth [] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30 };
uint16_t year;
uint16_t days = epoch / 24;
uint16_t m;
uint8_t leap;
for (year = 0; ; ++year) {
leap = year % 4 == 0;
if (days < 365 + leap)
break;
days -= 365 + leap;
}
String years = String(year);
if (year < 10) {
years = "0" + years;
}
for (m = 1; m < 12; ++m) {
uint8_t daysPerMonth = daysInMonth[m - 1];
if (leap && m == 2)
++daysPerMonth;
if (days < daysPerMonth)
break;
days -= daysPerMonth;
}
String months = String(m);
if (m < 10) {
months = "0" + months;
}
String d = String(days + 1);
if (days < 10) {
d = "0" + d;
}
String request_time = years + "/" + months + "/" + d + "," + hours + ":" + minutes + ":" + seconds+"+04";// ATTENTION: set your time zone here manually
Serial.println(request_time);
request_time ="AT+CCLK=\"" + request_time + "\"";
MODEM.send(request_time);
if (MODEM.waitForResponse(100) != 1) {
return 0;
}
Serial.println(gsmAccess.getTime());
return 1;
}
Serial.println("Error");
return 0;
}
|
no seems that is not able to receive an udp packet in time, try to increase the delay time from 1000 to more like 10000 or higher, until when you are not able to receive something from the ntp server, if nothing happens try to change the ntp server ,if you tell me the country where you are i'll try to search the best available for you |
Hi Renne. I tried the delay but still not working maybe is the NTP server I am pointing at. I am in the UK any suggestion would welcome.
|
try one of this 143.210.16.201, 178.79.160.57, 217.114.59.3, 87.117.251.3 |
two other options are change the mobile operator and retry to run the key generation with ecc508 |
Hi Riccardo. I tried with all those but none seems to work. I found another that seems to respond better however I still get an error
OK
16:10:52.476 -> You're connected to the cellular network
16:10:52.476 ->
16:10:52.476 -> AT+USOCR=17
16:10:52.476 -> +USOCR: 0
16:10:52.476 ->
16:10:52.476 -> OK
16:10:52.511 -> AT+USOLI=0,2390
16:10:52.511 -> OK
16:10:52.549 -> AT+USOST=0,"130.88.200.4",123,48,"E30006EC0000000000000000314E31340000000000000000000000000000000000000000000000000000000000000000"
16:10:52.549 -> +USOST: 0,48
16:10:52.549 ->
16:10:52.549 -> OK
16:10:53.548 -> Error
16:10:53.548 -> Error: time not configured
I will try what you said and use a SIM card from another network.
|
ok no no still stop on parsing packet, fine Ruben let me know, i'm here to support you |
Hi Riccardo. I gave it another go by adding more time and a different NTP server and now it works!!!
Many many thanks for your help
|
nice nice i'm happy that works :), i'll close the issue again if you need reopen |
I am using MKR GSM 1400 and I tried to connect to the AWS but I am facing issue in connecting i used AWS_IOT_GSM.ino code.
Logs:
I also replaced the code to get time NTP time
still, am facing the issue.
The text was updated successfully, but these errors were encountered: