Upcoming maintenance
Dear Customers and Partners.
This website will be undergoing scheduled maintenance on June 14, 2023. Please be aware there may be disruption to the developer portal website and associated services during the scheduled maintenance period.
This upgrade is essential to ensure the continued performance, reliability, and security of Developer World.
We apologize for any inconvenience.
WiFi Add board: Connection Problem
-
@jp04 I have a brief question before continuing here.
Do you plan to connect to AWS IoT as you have the certificates and no password?
Could you think of using the Spresense SDK? -
@jens6151-0-1-1 Hi jens sorry I have been "offline" a bit. No I have not had chance to look at the library modification for using the ATWINC1500 shield due to my work load. I have not tested the "performance" of the Japanese IDY module (that use the EOL Telit wifi) .either but did run their example codes with no issues (after taking care of the version/red or yellow dots)
-
I don't really feel comfortable asking them why they chose an obsolete module
But hopefully once Spresense user base grows a little more we will have more add on boards to choose from and more wifi compatible libraries.
-
@CamilaSouza Perhaps ask them in a "japanese way" : Ask when or if they are planning to release a new version of the board , instead of asking why the decided to pick up that one :
-
@maxieaussie-0 said in WiFi Add board: Connection Problem:
lanning to release a new version of the board , instead of asking why the decided to pick up that one :
hahaha ok.
I emailed them asking,
If I get a response, I'll let you guys know. -
To close this topic.
I got it working, but
- Keep in mind that the verification of the certificate need a valid time. It will fail if you do not get the time e.g. by NTP in advance.
- You need to delete the existing certificate or it fails uploading.
- I modified the AtCmd_MQTTCONNECT function by adding parameters for certificates.
- Although the AWS log says it connects successfully the connection terminates and the log complains that an invalid session alive time is set (which cannot be set at all by AT commands)
Result: unusable for AWS-IOT despite successful connection.
Using the AWS-IOT SDK with the Spresense NuttX SDK or the wifi module via the integrated NuttX drivers works like a charm (once you know how to configure it correctly. See https://forum.developer.sony.com/topic/924/very-long-compile-build-time-for-examples/6)
for your reference
/* * SPRESENSE_WiFi.ino - GainSpan WiFi Module Control Program * Copyright 2019 Norikazu Goto * * This work is free software; you can redistribute it and/or modify it under the terms * of the GNU Lesser General Public License as published by the Free Software Foundation; * either version 2.1 of the License, or (at your option) any later version. * * This work is distributed in the hope that it will be useful, but without any warranty; * without even the implied warranty of merchantability or fitness for a particular * purpose. See the GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License along with * this work; if not, write to the Free Software Foundation, * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include <GS2200Hal.h> #include <GS2200AtCmd.h> #include "AppFunc.h" #include <File.h> #define CONSOLE_BAUDRATE 115200 #define MQTT_SRVR "xxxx-ats.iot.us-east-1.amazonaws.com" #define MQTT_PORT "8883" #define MQTT_CLI_ID "spresense" #define MQTT_TOPIC "xxxx" //#define ROOTCA_FILE "/mnt/spif/cert/root-CA.crt" //#define CERT_FILE "/mnt/spif/cert/spresense.cert.pem" //#define KEY_FILE "/mnt/spif/cert/spresense.private.key" #define ROOTCA_FILE "/mnt/sd0/cert/root-CA.crt.der" #define CERT_FILE "/mnt/sd0/cert/spresense.cert.pem.der" #define KEY_FILE "/mnt/sd0/cert/spresense.private.key" char rootCaFile[] = ROOTCA_FILE; char certFile[] = CERT_FILE; char keyFile[] = KEY_FILE; // the setup function runs once when you press reset or power the board void setup() { /* initialize digital pin LED_BUILTIN as an output. */ pinMode(LED0, OUTPUT); digitalWrite( LED0, LOW ); // turn the LED off (LOW is the voltage level) Serial.begin( CONSOLE_BAUDRATE ); // talk to PC /* Initialize SPI access of GS2200 */ Init_GS2200_SPI(); digitalWrite( LED0, HIGH ); // turn on LED /* Initialize AT Command Library Buffer */ AtCmd_Init(); /* GS2200 Association to AP */ App_InitModule(); App_ConnectAP(); AtCmd_SendCommand("AT+NTIMESYNC=1,133.243.238.244,10,0\r\n"); sleep(1); AtCmd_SendCommand("AT+GETTIME=?\r\n"); sleep(1); char escape[2]; escape[0] = 0x1B; escape[1] = 'W'; AtCmd_SendCommand("AT+TCERTDEL=SSL_CA\r\n"); sleep(1); static char buf[4096] = {0}; File myFile = File(rootCaFile); myFile.read(buf, myFile.size()); buf[myFile.size()] = 0; static char cmd[1024] = {0}; snprintf(cmd, 1024, "AT+TCERTADD=SSL_CA,0,%lu,0\r\n", myFile.size()); AtCmd_SendCommand(cmd); sleep(1); WiFi_Write( escape, 2 ); WiFi_Write( buf, myFile.size() ); sleep(1); AtCmd_SendCommand("AT+TCERTDEL=SSL_CLIENTCERT\r\n"); sleep(1); myFile = File(certFile); myFile.read(buf, myFile.size()); buf[myFile.size()] = 0; snprintf(cmd, 1024, "AT+TCERTADD=SSL_CLIENTCERT,0,%lu,0\r\n", myFile.size()); AtCmd_SendCommand(cmd); sleep(1); WiFi_Write( escape, 2 ); WiFi_Write( buf, myFile.size() ); sleep(1); AtCmd_SendCommand("AT+TCERTDEL=SSL_CLIENTKEY\r\n"); sleep(1); myFile = File(keyFile); myFile.read(buf, myFile.size()); buf[myFile.size()] = 0; snprintf(cmd, 1024, "AT+TCERTADD=SSL_CLIENTKEY,0,%lu,0\r\n", myFile.size()); AtCmd_SendCommand(cmd); sleep(1); WiFi_Write( escape, 2 ); WiFi_Write( buf, myFile.size() ); sleep(1); } char server_cid = 0; bool served = false; uint16_t len, count=0; ATCMD_MQTTparams mqttparams; // the loop function runs over and over again forever void loop() { ATCMD_RESP_E resp; ATCMD_NetworkStatus networkStatus; if (!served) { resp = ATCMD_RESP_UNMATCH; // Start a MQTT client ConsoleLog( "Start MQTT Client"); char randomClientId[32]; rand(); // for some reason the first call to rand() returns 0 snprintf(randomClientId, 32, "%s-%d", MQTT_CLI_ID, rand()); resp = AtCmd_MQTTCONNECT( &server_cid, (char *)MQTT_SRVR, (char *)MQTT_PORT, (char *) randomClientId, "", "", 1, "SSL_CA", "SSL_CLIENTCERT", "SSL_CLIENTKEY" ); if (resp != ATCMD_RESP_OK) { ConsoleLog( "No Connect!" ); delay(20000); return; } if (server_cid == ATCMD_INVALID_CID) { ConsoleLog( "No CID!" ); delay(2000); return; } do { resp = AtCmd_NSTAT(&networkStatus); } while (ATCMD_RESP_OK != resp); served = true; } else { ConsoleLog( "Start to send MQTT Message"); // Prepare for the next chunck of incoming data WiFi_InitESCBuffer(); // Start the loop to send the data strcpy( mqttparams.topic, MQTT_TOPIC ); mqttparams.QoS = 0; mqttparams.retain = 0; while( served ){ sprintf( mqttparams.message, "%d", count++ ); mqttparams.len = strlen( mqttparams.message ); if( ATCMD_RESP_OK == AtCmd_MQTTPUBLISH( server_cid, mqttparams ) ){ ConsolePrintf( "%d was sent\r\n", count-1 ); } delay(5000); // every 5 sec /* just in case something from GS2200 */ while( Get_GPIO37Status() ){ resp = AtCmd_RecvResponse(); if( ATCMD_RESP_DISCONNECT == resp ) served = false; // quite the loop } } } }
Modified AtCmd_MQTTCONNECT inside the library.
ATCMD_RESP_E AtCmd_MQTTCONNECT( char *cid, char *host, char *port, char *clientID, char *UserName, char *Password, int SSLFlag, char *CertificateName, char *ClientCertificateName, char *ClientKeyName ) { ATCMD_RESP_E resp=ATCMD_RESP_UNMATCH; char cmd[180]; char *result; sprintf( cmd, "AT+MQTTCONNECT=%s,%s,%s,%s,%s,%d,%s,%s,%s,300\r\n", host, port, clientID, UserName, Password, SSLFlag, CertificateName, ClientCertificateName, ClientKeyName );
-
@jens6151-0-1-1
Thank you so much for sharing your solution!
That's very helpful for the community -
If you are experiencing connection problems with your WiFi Add board, here are some steps you can try to troubleshoot the issue:
Check the power supply: Ensure that the WiFi Add board is properly powered. Check that the power source is connected and working correctly. If the power supply is not adequate, the board may not function properly.
Check the antenna: Make sure that the antenna is securely connected to the WiFi Add board. A loose or disconnected antenna can cause connection issues.
Check the network settings: Verify that the network settings on the board are correctly configured. Make sure that the SSID, password, and security settings match those of your wireless network.