loading

A few weeks ago, I wrote a posting about WizFi250-CSI as below.

https://www.instructables.com/id/WizFi250-CSIC-Script-Interpreter-for-rapid-prototy/

And now, I will demonstrate a serial-to-wifi application using WizFi250-CSI.

With WizFi250-CSI, I finished the serial-to-wifi application in 10 minutes. (Writing and testing).

Step 1: Description of WizFi250-CSI.h

You can any script with this "WizFi250-CSI.h" file.

This header file include all API function which you can use for a script file.

For all "WizFi250-CSI.h", you can refer to the below link.

http://ilikethisplus.tistory.com/34

https://www.instructables.com/id/WizFi250-CSIC-Script-Interpreter-for-rapid-prototy/step2/WizFi250-CSIh/

Step 2: Write "C Script File" for Serial-To-WiFi

Please refer to the below script file.

<p>#include "WizFi250-CSI.h"</p><p>void main(void)
{
  struct sockaddr_in stSockAddr;
  int Res, result;</p><p>  // Join to AP
  if ( result = wifi_join("WizFiDemoAP", "wpa2", "12345678", 0, 0, 0)!=0 )
  {
    printf("wifi_join error : %d", result);
    return;
  }</p><p>  // TCP Socket
  int SocketFD = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
  if (-1 == SocketFD)
  {
    printf("cannot create socket\r\n");
    return;
  }</p><p>  // Define Server IP, Port
  memset(&stSockAddr, 0, sizeof(stSockAddr));
  stSockAddr.sin_family = AF_INET;
  stSockAddr.sin_addr.s_addr = inet_addr("192.168.3.54");
  stSockAddr.sin_port = htons(6000);</p><p>  if (-1 == connect(SocketFD, (struct sockaddr *)&stSockAddr, sizeof(stSockAddr)))
  {
    printf("connect failed\r\n");
    close(SocketFD);
    return;
  }</p><p>  char szData[256];
  int length = 0;</p><p>  // Set GPIO12 input-pin.
  pinMode(GPIO12, 1);</p><p>  while(1)
  {
    length = uart_rx(0, szData, 256);
    if ( length>0 )
    {
      pinOut(GPIO12, 0);
      result = send(SocketFD, szData, length, 0);
      pinOut(GPIO12, 1);
      if ( result<0 )   break;
    }</p><p>    length = recv(SocketFD, szData, sizeof(szData), MSG_DONTWAIT);
    if ( length==0 )
    {
      break;
    }
    else if ( length<0 )
    {
      if ( sock_error==EAGAIN )         continue;</p><p>      printf("<%d,%d>", length, sock_error);
      break;
    }
    else
    {
      pinOut(GPIO12, 0);
      uart_tx(0, szData, length);
      pinOut(GPIO12, 1);
    }</p><p>  }</p><p>  printf("Disconnected (%d) \r\n", length);
  close(SocketFD);</p><p>  return;
}</p>

Or you can refer the below link.

http://ilikethisplus.tistory.com/38

Step 3: Upload "C Script File" for Serial-To-WiFi

At first, you should upload(or write) script file as attached picture.

Step 4: Run "C Script File"

Now, if you reset the WizFi250-CSI, Serial-To-WiFi application will run as attached picture.

Data-communication worked well in both Serial-to-WiFi and WiFi-to-Serial.

Step 5: Conclusion

Benefit of Serial-To-WiFi using WizFi250-CSI

  • User can select TCP/UDP and Server/Client in source code level.
  • It's very similar standard C.
  • User can define LED indications(GPIO or ADC)
  • User doesn't need serial-command(AT Command).
  • User can implement data-packing of network-packet in socket-API.
  • Multi sockets are available
  • User doesn't need any tool or web server for configuration.

About This Instructable

453views

17favorites

License:

More by SteveK2:Serial-To-WiFi Using WizFi250-CSI WizFi250-CSI(C Script Interpreter) for rapid-prototyping, DIY, IoT-startup or students. 
Add instructable to: