<?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>Thingy91: Changing the Network Mode during runtime</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/56128/thingy91-changing-the-network-mode-during-runtime</link><description>Hello, I am writing a Program where I use GPS and NBIoT. Recently, I wanted to combine the default GPS example code with an NBIoT Code, that connects to a TCP Server and when I tested it, either the Server Connection or the GPS failed. So I looked up</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 03 Jan 2020 12:12:41 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/56128/thingy91-changing-the-network-mode-during-runtime" /><item><title>RE: Thingy91: Changing the Network Mode during runtime</title><link>https://devzone.nordicsemi.com/thread/227393?ContentTypeID=1</link><pubDate>Fri, 03 Jan 2020 12:12:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:340d74e2-6762-42c7-8109-e0d0740ddf23</guid><dc:creator>Bergmann</dc:creator><description>&lt;p&gt;Ok, i found the solution by myself:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#include &amp;lt;zephyr.h&amp;gt;
#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;uart.h&amp;gt;
#include &amp;lt;string.h&amp;gt;
#include &amp;lt;net/socket.h&amp;gt;
static int at_command_socket;
int bytes_sent, bytes_read;
static u8_t at_command1[256] = &amp;quot;AT+CFUN=4\r\n&amp;quot;;
static u8_t at_command2[256] = &amp;quot;AT+CFUN=1\r\n&amp;quot;;
static u8_t at_command3[256] = &amp;quot;AT%XSYSTEMMODE=0,1,0,0\r\n&amp;quot;;
static u8_t at_command4[256] = &amp;quot;AT%XSYSTEMMODE=0,0,1,0\r\n&amp;quot;;
static u8_t at_command5[256] = &amp;quot;AT%XSYSTEMMODE?\r\n&amp;quot;;
static char result[256];

void ATCFUN4(){
      bytes_sent = send(at_command_socket, at_command1, strlen(at_command1), 0);
      bytes_read = recv(at_command_socket, result, sizeof(result), 0);
}
void ATCFUN1(){      
      bytes_sent = send(at_command_socket, at_command2, strlen(at_command2), 0);
      bytes_read = recv(at_command_socket, result, sizeof(result), 0);
}

void NBIoT_Mode(){      
      bytes_sent = send(at_command_socket, at_command3, strlen(at_command3), 0);
      bytes_read = recv(at_command_socket, result, sizeof(result), 0);
}


void GPS_Mode(){    
      bytes_sent = send(at_command_socket, at_command4, strlen(at_command4), 0);
      bytes_read = recv(at_command_socket, result, sizeof(result), 0);
}


void read_mode(){
      bytes_sent = send(at_command_socket, at_command5, strlen(at_command5), 0);
      bytes_read = recv(at_command_socket, result, sizeof(result), 0);
      printk(&amp;quot;RECEIVED FROM recv(): %s\n&amp;quot;, result);
}


void main(void)
{
  at_command_socket = socket(AF_LTE, 0, NPROTO_AT);
  while (1)
    {
      ATCFUN4();
      k_sleep(100);
      GPS_Mode();
      k_sleep(200);
      ATCFUN1();
      k_sleep(100);
      read_mode();
      k_sleep(100);
      ATCFUN4();
      k_sleep(100);
      NBIoT_Mode();
      k_sleep(200);
      ATCFUN1();
      k_sleep(100);
      read_mode();
      k_sleep(100);
  }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I only have to declarate the variables and the socket once at the beginning of the code. Now I works:&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1578053554888v1.png" /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Thingy91: Changing the Network Mode during runtime</title><link>https://devzone.nordicsemi.com/thread/227392?ContentTypeID=1</link><pubDate>Fri, 03 Jan 2020 12:11:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c61ffb3c-05e2-4800-8b62-303693f0ce4c</guid><dc:creator>MJD093</dc:creator><description>&lt;p&gt;One of the non-official examples might be more appealing to you.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/Rallare/fw-nrfconnect-nrf/blob/nrf9160_samples/samples/nrf9160/simple_at/src/main.c"&gt;https://github.com/Rallare/fw-nrfconnect-nrf/blob/nrf9160_samples/samples/nrf9160/simple_at/src/main.c&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;See the above non-official sample for an application that simply runs a list of at commands (defined in &amp;#39;at_commands[]&amp;#39;).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Thingy91: Changing the Network Mode during runtime</title><link>https://devzone.nordicsemi.com/thread/227385?ContentTypeID=1</link><pubDate>Fri, 03 Jan 2020 10:48:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dad6f10e-4c45-4177-b590-d7904d2cc70c</guid><dc:creator>Bergmann</dc:creator><description>&lt;p&gt;Hi, I updated the modem FW to 1.1.0 and am in the master branch of NCS&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1578047006394v2.png" /&gt;&lt;/p&gt;
&lt;p&gt;If I try to do it manually in the LTE Monitor, I can change it with no problem:&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1578046980369v1.png" /&gt;&lt;/p&gt;
&lt;p&gt;Is there maybe another way to run AT commands during runtime? I tried to run the code from above again and then I saw that I get no OKs each time, I want to change the system mode:&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1578047515467v1.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;I have done it with this code in the example above:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;      static int at_command_socket;
      int bytes_sent, bytes_read;
      static u8_t at_command[256] = &amp;quot;AT+CFUN=4\r\n&amp;quot;;
      static char result[256];
      at_command_socket = socket(AF_LTE, 0, NPROTO_AT);
      int bytes_to_send = strlen(at_command);
      bytes_sent = send(at_command_socket, at_command, bytes_to_send, 0);
      bytes_read = recv(at_command_socket, result, sizeof(result), 0);
      printk(&amp;quot;RECEIVED FROM recv(): %s\n&amp;quot;, result);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;And I am not sure if this is the write way to do it for my case.&amp;nbsp;&lt;br /&gt;Do you maybe have another code example, that runs AT Commands during a program?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks for your for your answers and your help!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Thingy91: Changing the Network Mode during runtime</title><link>https://devzone.nordicsemi.com/thread/227380?ContentTypeID=1</link><pubDate>Fri, 03 Jan 2020 10:29:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5c6dc033-f940-49ad-a49e-a3e14a7d136e</guid><dc:creator>&amp;#216;yvind</dc:creator><description>&lt;p&gt;Hello,&amp;nbsp;&lt;br /&gt;&lt;br /&gt;I am able to run your code, but it does not change system mode. What version of NCS and modem FW are you running? Have you tried with the AT Client, to verify that it can change state?&amp;nbsp;&lt;br /&gt;&lt;br /&gt;Kind regards,&amp;nbsp;&lt;br /&gt;Øyvind&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>