<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Getting console Input from within a Zephyr shell command</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/77274/getting-console-input-from-within-a-zephyr-shell-command</link><description>I&amp;#39;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&amp;#39;t work, so I was going to use the getchar() command to read it in as part of the command operation. getchar doesn</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Sat, 26 Feb 2022 04:12:21 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/77274/getting-console-input-from-within-a-zephyr-shell-command" /><item><title>RE: Getting console Input from within a Zephyr shell command</title><link>https://devzone.nordicsemi.com/thread/355123?ContentTypeID=1</link><pubDate>Sat, 26 Feb 2022 04:12:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f369fa54-9754-4b89-a452-40f01b8ecfd9</guid><dc:creator>Aslamies</dc:creator><description>&lt;p&gt;Here is my implementation:&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;char* shell_getline(const struct shell *shell, char *buf, const size_t len) {
    if (!buf)
        return NULL;
    
    char *p = buf;
    memset(buf, 0, len);

    for (size_t i = 0; i &amp;lt; (len - 1); i++) {
        char c;
        size_t cnt;

        shell-&amp;gt;iface-&amp;gt;api-&amp;gt;read(shell-&amp;gt;iface, &amp;amp;c, sizeof(c), &amp;amp;cnt);
        while (cnt == 0) {    
            k_busy_wait(100);
            shell-&amp;gt;iface-&amp;gt;api-&amp;gt;read(shell-&amp;gt;iface, &amp;amp;c, sizeof(c), &amp;amp;cnt);
        }
        shell-&amp;gt;iface-&amp;gt;api-&amp;gt;write(shell-&amp;gt;iface, &amp;amp;c, sizeof(c), &amp;amp;cnt);
        if (c == &amp;#39;\n&amp;#39; || c == &amp;#39;\r&amp;#39;) {
            break; // end of line
        }
        *p++ = c;
    }

    return buf;
}
&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Getting console Input from within a Zephyr shell command</title><link>https://devzone.nordicsemi.com/thread/319523?ContentTypeID=1</link><pubDate>Mon, 12 Jul 2021 07:45:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8c45e8e6-16ff-4e60-b9cf-dd44955761f4</guid><dc:creator>&amp;#216;yvind</dc:creator><description>&lt;p&gt;Randall,&amp;nbsp;&lt;/p&gt;
[quote user="Philrt"]I&amp;#39;m using the 1.5.1 SDK.&amp;nbsp; My modem firmware is 1.3.0 although I can&amp;#39;t see how that matters.&amp;nbsp; My code looks like below;[/quote]
&lt;p&gt;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.&amp;nbsp;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;m&lt;span&gt;fw&lt;/span&gt;_nrf9160_1.2.3&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;m&lt;span&gt;fw&lt;/span&gt;_nrf9160_1.1.4&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/1.5.1/nrf/releases/release-notes-1.5.1.html#supported-modem-firmware"&gt;Please see &amp;quot;Supported Modem Version&amp;quot; in the NCS release notes of v1.5.1.&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;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.&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;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)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;As certificates are written to the modem, the modem FW is highly relevant to provide correct support.&lt;/p&gt;
&lt;p&gt;Please &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/1.6.0/nrf/samples/nrf9160/modem_shell/README.html"&gt;have a look at the Modem Shell provided in NCS 1.6.0&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;br /&gt;Øyvind&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Getting console Input from within a Zephyr shell command</title><link>https://devzone.nordicsemi.com/thread/319441?ContentTypeID=1</link><pubDate>Fri, 09 Jul 2021 17:26:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6db20824-bf03-4f23-a196-0bc6579fbc49</guid><dc:creator>Randall</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;span&gt;&amp;Oslash;yvind,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I don&amp;#39;t get any error messages.&amp;nbsp; With the different attempts that I try it either locks up, always returns 0 or Bus Faults.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I&amp;#39;m using the 1.5.1 SDK.&amp;nbsp; My modem firmware is 1.3.0 although I can&amp;#39;t see how that matters.&amp;nbsp; My code looks like below;&lt;br /&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;  char *certBuf = NULL, *certPtr;
  char newByte;
  int err;

  certBuf = k_malloc(2048);
  if ( certBuf == NULL )
  {
    shell_error( shell, &amp;quot;Insufficient memory to store cert&amp;quot; );
    return(-1);
  }

  certPtr = certBuf;
  memset( certBuf, 0, 2048 );
  while( 1 )
  {
    newByte = console_getchar();
    if ( newByte == 0x1B ) 
    {
      shell_warn( shell, &amp;quot;certification transmission terminated\n&amp;quot; );
      k_free(certBuf);
      return(-1);
    }
    shell_print( shell, &amp;quot;Received = %c&amp;quot;, newByte );
    *certPtr++ = newByte;
    if( certPtr - certBuf &amp;gt;= 2048 )
    {
      shell_error( shell, &amp;quot;certificate too large\n&amp;quot; );
      k_free(certBuf);
      return(-1);
    }
    if ( strstr( certBuf, &amp;quot;-----END CERTIFICATE-----\n&amp;quot; ) )
    { 
      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, &amp;quot;GCLOUD_CA_CERTIFICATE err: %d %s\n&amp;quot;, err, strerror(err));
      }

      k_free(certBuf);
      return err;
    }
  }
&lt;/pre&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;This produces a bus fault at console_getchar().&amp;nbsp; If I put a console_init() in my code startup, then it siimply breaks my shell (I get a shell prompt, but it won&amp;#39;t take commands). if I use getchar() instead of console_getchar().&amp;nbsp; getchar just returns 0.&amp;nbsp; when when I&amp;#39;m pasting in characters.&amp;nbsp; And I can&amp;#39;t get it to see the esc character to exit.&lt;br /&gt;&lt;br /&gt;Randall&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Getting console Input from within a Zephyr shell command</title><link>https://devzone.nordicsemi.com/thread/319341?ContentTypeID=1</link><pubDate>Fri, 09 Jul 2021 11:19:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:21c4e51e-d1c2-4b5e-bbe7-2b8f51b4e977</guid><dc:creator>&amp;#216;yvind</dc:creator><description>&lt;p&gt;Hello,&amp;nbsp;&lt;br /&gt;&lt;br /&gt;Can you please provide more information about your issue? Are you getting an error message? What version of NCS are you running? Modem FW version? Please provide more information.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;Note that we are currently in our summer vacation period and responses are expected to be slow due to availability of resources.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;br /&gt;Øyvind&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>