title: ESP8266 - Connect to TCP Server (in C)
body: <p>I am currently trying to get the esp8266 to connect to my http server. Connecting to my local wifi network works but if I try to connect to my server I get this error on the terminal window: </p>
  
  <blockquote>
    <p>Fatal exception 9(LoadStoreAlignmentCause):
    epc1=0x4026027b, epc2=0x00000000, epc3=0x00000000, excvaddr=0x00000011, depc=0x00000000</p>
  </blockquote>
  
  <p>In the <code>user_init</code> function I call <code>check_ip()</code> which handles the tcp connection and looks like this:</p>
  
  <pre><code>LOCAL void ICACHE_FLASH_ATTR check_ip(void){
      struct espconn conn;
      struct ip_info ipconf;
      esp_tcp tcp;
      uint8 ipAddr[4] = {1,2,3,4};
      uint32 localPort = espconn_port();
      bool res = wifi_get_ip_info(STATION_IF, &amp;ipconf);
      if(!res)
          os_printf("No Success.");
      else{
          os_memcpy(tcp.local_ip,&amp;ipconf.ip,4);
          if(wifi_station_get_connect_status() == STATION_GOT_IP &amp;&amp; ipconf.ip.addr != 0){
              os_printf("Got IP Address.\n");
  
              tcp.remote_port = 80;
              tcp.local_port = espconn_port();
              os_memcpy(tcp.remote_ip,ipAddr,4);
  
              conn.type = ESPCONN_TCP;
              conn.state = ESPCONN_NONE;
              conn.proto.tcp = &amp;tcp;
  
              espconn_regist_connectcb(&amp;conn,tcp_connect_cb);
              espconn_regist_reconcb(&amp;conn,tcp_recon_cb);
  
              espconn_connect(&amp;conn);
              os_timer_disarm(&amp;timer);
          } else {
              os_timer_setfn(&amp;timer,(os_timer_func_t*)check_ip,NULL);
              os_timer_arm(&amp;timer,100,0); //recall function after 100ms, don't repeat
          }
      }
  }
  </code></pre>
  
  <p>Any help is very much appreciated.</p>