Sony's Developer World forum

    • Home
    • Forum guidelines

    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

    Spresense
    5
    48
    8089
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    This topic has been deleted. Only users with topic management privileges can see it.
    • M
      maxieaussie 0 @jp04 last edited by

      @jp04 yes I had to do this too btw @CamilaSouza if you talk to IDY could you please ask them why they decided to use an OBSOLETED and very old Telit wifi module? (I can't believe it when I checked the actual module!)

      Just for funI am now trying to use a more modern ATWINC1500 (Microchip/Atmel) just using an Adafruit shield but left with a lot of homework as Wifi101 library is incompatible with spresense (conflict/duplicate in the socket module-data types are not even the same).

      While spresense is OK for homegrown project for anyone who is considering to start with this platform and then take it to "production" might be disappointed . I would suggest to look at solutions form Microcontroller companies (Renesas, Microchip, ST) should your goal is "production". At the end of the day you are most likely would be unable to buy the Sony MCU unless you are ordering a huge qty from Sony imho.

      J C 2 Replies Last reply Reply Quote
      • J
        jens6151 0 1 1 @maxieaussie 0 last edited by jens6151 0 1 1

        @maxieaussie-0
        What exactly did you have to do too?
        You referred to modifying the library. You used that module too? Can you give any feedback on the performance of this very old module? I am looking for something to stream camera images (1280x960, jpeg, can be even 1fps) over network. Just for hobby, 1 piece.

        This Wifi add on board itself is also EOL.

        Let me make one guess. There are only a very few wifi/BLE/LTE modules available that are certified for usage in Japan. About 90% (my feeling) is not allowed to be used, even for prototyping. Since a few years there is a system where you can apply for exceptions if the module is FCC certified. But it is limited to 6 months, then you must dispose the hardware ...

        For what I have seen on the vendors' sites as documentation or samples or availability .. forget about all 3rd party modules. (sorry to overgeneralize if I missed a good vendor)

        M 1 Reply Last reply Reply Quote
        • J
          jp04 @jens6151 0 1 1 last edited by

          @jens6151-0-1-1 I am sorry for my late response. Thank you for continuing to help me with this issue. I really don't know what else to do, once I execute those commands I get OK as a response, however after sending the information I get "SPI Timeout".

          10:38:21.758 -> >AT+TCERTDEL=SSL_CACERT
          10:38:21.758 -> OK
          10:38:21.758 -> GS Response: 1
          10:38:21.758 -> >AT+TCERTDEL=SSL_CLIENTCERT
          10:38:21.758 -> OK
          10:38:21.758 -> GS Response: 1
          10:38:21.758 -> >AT+TCERTADD=SSL_CACERT,1,1472,0
          10:38:21.795 -> OK
          10:38:21.795 -> GS Response: 1
          10:38:24.794 -> >AT+TCERTADD=SSL_CLIENTCERT,1,1424,0
          10:38:24.794 -> OK
          10:38:24.794 -> GS Response: 1
          10:38:27.844 -> >AT+TCERTADD=SSL_CLIENTKEY,1,1704,0
          10:38:27.844 -> OK
          10:38:27.844 -> GS Response: 1
          10:38:30.859 -> >AT+MQTTCONNECT=XXX,8883,User1,,,1,SSL_CACERT,SSL_CLIENTCERT,SSL_CLIENTKEY,30
          10:38:30.859 -> OK
          
          
          10:38:35.895 -> >AT+MQTTPUBLISH=
          10:38:55.877 -> SPI: Timeout
          
          J 1 Reply Last reply Reply Quote
          • J
            jens6151 0 1 1 @jp04 last edited by jens6151 0 1 1

            @jp04 I cannot see what you send. It is only AT+MQTTPUBLISH=

            Are you sending according to the documentation? Note the <ESC>N<CID>

            This is the documentation
            This Command is used to send an Application Messages from client to the server. Command Syntax

            AT+MQTTPUBLISH=<CID>,<TopicName>,<Length>,<Qos>[,<Retain Flag>]
            

            MCU sends MQTT data using the following Escape <ESC> sequence:

            <ESC>N<CID><DataofaboveLength>
            

            Also connect should return not just OK

            <IP>:<xxx.xxx.xxx.xxx>
            <CID>
            OK
            
            J 1 Reply Last reply Reply Quote
            • J
              jp04 @jens6151 0 1 1 last edited by jp04

              @jens6151-0-1-1 Hi. I just uploaded the code related with the certifications. Already fixed the MQTT Publish problem but i think the problem persist on the certifications.

              AtCmd_SendCommand( (char *) "AT+TCERTADD=SSL_CACERT,1,1472,0\r\n");
              sleep(1);
              WiFi_Write( escape, 2 );
              sleep(1);
              WiFi_Write(ca_cert, strlen(ca_cert));
              sleep(1);
              AtCmd_SendCommand( (char *) "AT+TCERTADD=SSL_CLIENTCERT,1,1424,0\r\n");
                sleep(1);
                WiFi_Write( escape, 2 );
                sleep(1);
                WiFi_Write(client_cert, strlen(client_cert));
                sleep(1);
                AtCmd_SendCommand( (char *) "AT+TCERTADD=SSL_CLIENTKEY,1,1704,0\r\n");
                sleep(1);
                WiFi_Write( escape, 2 );
                sleep(1);
                WiFi_Write(client_key, strlen(client_key));
              

              Output:

              15:04:02.476 -> >AT+MQTTCONNECT=XXX,8883,User1,,,1,SSL_CACERT,SSL_CLIENTCERT,SSL_CLIENTKEY,30
              15:04:02.476 -> OK
              15:04:02.476 -> GS Response: 1
              15:04:02.476 -> No CID!
              15:04:04.503 -> >AT+MQTTPUBLISH=0,XXX,322,0,0
              15:04:04.503 -> OK
              15:04:04.503 -> GS Response: 1
              15:04:09.534 -> >AT+MQTTPUBLISH=0,XXX,322,0,0
              15:04:09.534 -> OK
              15:04:09.534 -> GS Response: 1
              15:04:14.534 -> >AT+MQTTPUBLISH=0,XXX,322,0,0
              15:04:14.534 -> IP:XXX
              15:04:14.534 -> ERROR
              15:04:14.534 -> GS Response: 4
              
              J 1 Reply Last reply Reply Quote
              • J
                jens6151 0 1 1 @jp04 last edited by

                @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?

                1 Reply Last reply Reply Quote
                • M
                  maxieaussie 0 @jens6151 0 1 1 last edited by

                  @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)

                  1 Reply Last reply Reply Quote
                  • C
                    CamilaSouza DeveloperWorld @maxieaussie 0 last edited by

                    @maxieaussie-0

                    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.

                    M 1 Reply Last reply Reply Quote
                    • M
                      maxieaussie 0 @CamilaSouza last edited by

                      @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 :😊

                      C 1 Reply Last reply Reply Quote
                      • C
                        CamilaSouza DeveloperWorld @maxieaussie 0 last edited by

                        @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.

                        J 1 Reply Last reply Reply Quote
                        • J
                          jens6151 0 1 1 @CamilaSouza last edited by

                          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 );
                          
                          
                          
                          
                          C 1 Reply Last reply Reply Quote
                          • C
                            CamilaSouza DeveloperWorld @jens6151 0 1 1 last edited by

                            @jens6151-0-1-1

                            Thank you so much for sharing your solution!
                            That's very helpful for the community

                            1 Reply Last reply Reply Quote
                            • M
                              MikeClark last edited by

                              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.

                              1 Reply Last reply Reply Quote
                              • First post
                                Last post
                              Developer World
                              Copyright © 2021 Sony Group Corporation. All rights reserved.
                              • Contact us
                              • Legal