Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
Tags
- SSL Server
- Neul
- OpenSSL
- Cat M1
- WIZwiki-W7500
- NB-IoT
- 안드로이드
- script
- W7500
- KT
- IOT
- IoTMakers
- Gainspan
- MQTT
- WizFi210
- SKT
- 오픈 하우스
- C Script
- ThingPlug
- micropython
- AT+MEVTFORM
- cloud
- PicoC
- LoRa
- WizFi310
- WiFi
- AT+FSOCK
- ESP8266
- SerialPassthrough
- WizFi250
Archives
- Today
- Total
IoT Wireless
Serial-To-WiFi(2 UART) using WizFi250 CSI 본문
Serial-To-WiFi using WizFi250 CSI를 조금 변경해서 UART 2개에 대한 Serial-To-WiFi 기능을 하는 C Script를 만들었다.
#include "WizFi250-CSI.h" void main(void) { struct sockaddr_in stSockAddr; int Res, result; // Join to AP if ( result = wifi_join("WizFiDemoAP", "wpa2", "12345678", 0, 0, 0)!=0 ) { printf("wifi_join error : %d", result); return; } //////////////////////////////////////////////////////////////////////////////////// // TCP Socket for UART 1 int SocketFD1 = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); if (-1 == SocketFD1) { printf("cannot create socket\r\n"); return; } // 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); if (-1 == connect(SocketFD1, (struct sockaddr *)&stSockAddr, sizeof(stSockAddr))) { printf("connect failed\r\n"); close(SocketFD1); return; } //////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////// // TCP Socket for UART 2 int SocketFD2 = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); if (-1 == SocketFD2) { printf("cannot create socket\r\n"); return; } // 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(6001); if (-1 == connect(SocketFD2, (struct sockaddr *)&stSockAddr, sizeof(stSockAddr))) { printf("connect failed\r\n"); close(SocketFD2); return; } //////////////////////////////////////////////////////////////////////////////////// char szData[256]; int length = 0; // Set GPIO12 input-pin. pinMode(GPIO12, 1); while(1) { //////////////////////////////////////////////////////////////////////////////////////// // UART 1 length = uart_rx(0, szData, 256); if ( length>0 ) { pinOut(GPIO12, 0); result = send(SocketFD1, szData, length, 0); pinOut(GPIO12, 1); if ( result<0 ) break; } length = recv(SocketFD1, szData, sizeof(szData), MSG_DONTWAIT); if ( length==0 ) { break; } else if ( length<0 ) { if ( sock_error==EAGAIN ) continue; printf("<%d,%d>", length, sock_error); break; } else { pinOut(GPIO12, 0); uart_tx(0, szData, length); pinOut(GPIO12, 1); } //////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////// // UART 2 length = uart_rx(1, szData, 256); if ( length>0 ) { pinOut(GPIO12, 0); result = send(SocketFD2, szData, length, 0); pinOut(GPIO12, 1); if ( result<0 ) break; } length = recv(SocketFD2, szData, sizeof(szData), MSG_DONTWAIT); if ( length==0 ) { break; } else if ( length<0 ) { if ( sock_error==EAGAIN ) continue; printf("<%d,%d>", length, sock_error); break; } else { pinOut(GPIO12, 0); uart_tx(1, szData, length); pinOut(GPIO12, 1); } //////////////////////////////////////////////////////////////////////////////////////// } printf("Disconnected (%d) \r\n", length); close(SocketFD1); return; }
'IoT Platform(Script)' 카테고리의 다른 글
Raspberry Pi Pico MicroPython Ethernet (0) | 2022.01.25 |
---|---|
Serial-To-WiFi using WizFi250 CSI (0) | 2015.06.26 |
WizFi250-CSI(C Scripting Interpreter) Header File (0) | 2015.05.29 |
Software diagram of WizFi250-PicoC (0) | 2015.04.28 |
Introduction to Embedded Script Engine (0) | 2015.04.28 |