This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Getting console Input from within a Zephyr shell command

I'm trying to create a Zephyr Shell command where I can write a certificate to the modem.  Putting the certificate in the command line doesn't work, so I was going to use the getchar() command to read it in as part of the command operation.  getchar doesn't work.  If I try to use console_getchar() it crashes.  If I power up with console_init then the shell locks up.

I was hoping that there was going to be a shell_getchar() or something similar to the shell_print which I could use to get input.  But I haven't found anything like that.

Is there a way to crack this nut?

Parents Reply Children
  • Hi Øyvind,

    I don't get any error messages.  With the different attempts that I try it either locks up, always returns 0 or Bus Faults.

    I'm using the 1.5.1 SDK.  My modem firmware is 1.3.0 although I can't see how that matters.  My code looks like below;

      char *certBuf = NULL, *certPtr;
      char newByte;
      int err;
    
      certBuf = k_malloc(2048);
      if ( certBuf == NULL )
      {
        shell_error( shell, "Insufficient memory to store cert" );
        return(-1);
      }
    
      certPtr = certBuf;
      memset( certBuf, 0, 2048 );
      while( 1 )
      {
        newByte = console_getchar();
        if ( newByte == 0x1B ) 
        {
          shell_warn( shell, "certification transmission terminated\n" );
          k_free(certBuf);
          return(-1);
        }
        shell_print( shell, "Received = %c", newByte );
        *certPtr++ = newByte;
        if( certPtr - certBuf >= 2048 )
        {
          shell_error( shell, "certificate too large\n" );
          k_free(certBuf);
          return(-1);
        }
        if ( strstr( certBuf, "-----END CERTIFICATE-----\n" ) )
        { 
          err = modem_key_mgmt_delete( GCLOUD_SEC_TAG, MODEM_KEY_MGMT_CRED_TYPE_CA_CHAIN );
          err = modem_key_mgmt_write( GCLOUD_SEC_TAG, MODEM_KEY_MGMT_CRED_TYPE_CA_CHAIN,
                                      certBuf, strlens(certBuf) );
          if (err != 0) 
          {
            shell_error( shell, "GCLOUD_CA_CERTIFICATE err: %d %s\n", err, strerror(err));
          }
    
          k_free(certBuf);
          return err;
        }
      }
    

    This produces a bus fault at console_getchar().  If I put a console_init() in my code startup, then it siimply breaks my shell (I get a shell prompt, but it won't take commands). if I use getchar() instead of console_getchar().  getchar just returns 0.  when when I'm pasting in characters.  And I can't get it to see the esc character to exit.

    Randall  

  • Randall, 

    Randall said:
    I'm using the 1.5.1 SDK.  My modem firmware is 1.3.0 although I can't see how that matters.  My code looks like below;

    This matters a lot as NCS 1.5.1 is not tested with modem FW 1.6.0. Currently there are two versions that are supported in NCS v1.5.1. 

    • mfw_nrf9160_1.2.3

    • mfw_nrf9160_1.1.4

    Please see "Supported Modem Version" in the NCS release notes of v1.5.1.

    Modem FW 1.3.0 is supported by NCS v1.6.0. What version of the nRF9160 are you working on? From the download page of modem FW.

    Note that this modem firmware is targeted nRF9160 SiP Revision 2 
    It can be used for nRF9160 SiP Revision 1, but only for testing and development
    It cannot be used for engineering samples of Revision 1 (e.g. DKs or Thingy:91 with version older than v0.9.0) 
    After you upgrade to MFW 1.3.0 it is not recommended to downgrade to mfw 1.2.x or mfw 1.1.x.(potential file system issues)

    As certificates are written to the modem, the modem FW is highly relevant to provide correct support.

    Please have a look at the Modem Shell provided in NCS 1.6.0

    Kind regards,
    Øyvind

Related