Giter Site home page Giter Site logo

microchiptech / pic32mzw1_uart_wifi_bridge Goto Github PK

View Code? Open in Web Editor NEW
4.0 4.0 1.0 22.81 MB

"IoT Made Easy!" - This example application enable a Transparent UART Bridge over Wi-Fi based on TCP/IP Client/Server

License: Other

Makefile 7.38% Batchfile 0.01% C 92.37% Assembly 0.24%
wifi bridge uart wfi32 pic32mzw1 curiosity-board iot-board

pic32mzw1_uart_wifi_bridge's Introduction

Enable UART-WiFi Bridge

"Wireless Made Easy!" - This example application enable a Transparent UART Bridge over Wi-Fi based on TCP/IP Client/Server

Devices: WFI32E01

โš  Disclaimer

THE SOFTWARE ARE PROVIDED "AS IS" AND GIVE A PATH FOR SELF-SUPPORT AND SELF-MAINTENANCE.

This repository contains unsupported example code intended to help accelerate client product development. It is not validated for production nor audited for security best-practices.

Note that while this repository is unsupported, Microchip welcome community contributions, and all pull-requests will be considered for inclusion into the repository.

Interact with peers in the community at WiFi Forum.

Description

This Transparent Wi-Fi (TCP) to UART Bridge supports both AP and Station Wi-Fi modes. The main purpose of this code example is to serve as a serial bridge: bridge a TCP connection over Wi-Fi to serial interface. Thus, it allows the WFI32E device to become a totally transparent Wi-Fi to Serial bridge. The UART-to-WiFi-TCP bridge transmits all incoming TCP bytes on a socket out of the WFI32E's UART module and all incoming UART bytes out of a TCP socket.

A TCP Server is running on the WFI32E AP Device. Its job is to listen for incoming connections at a port (47111) on the device's IP address. When a remote device (TCP Client) reaches out, the TCP Server creates a channel for the WFI32E Server and the remote client to communicate. The typical UART rates are 115 200 baud. So theorically, the time push up to 1400 Bytes (the maximum TCP packet size) out is around 130 milliseconds.

In this demo, the WFI32E is operating in AP mode and run the TCP Server. The Station device which run the TCP Client program can be a second WFI32E device or a Computer with Wi-Fi adapter or a Smartphone.

The bridge can be useseful in many applications such as Motor control, maintenance, Field bus, etc...

  • In Motor control applications, the Transparent UART-WiFi Bridge can provide a galvanic isolation between the target (generally the motor control part) and a real-time debugging tool such as MPLAB(r) Harmony X2C Scope which allow to "watch" or "plot" any global variable in an embedded application at run-time i.e. without halting the CPU. So very useful for motor control development.

  • With a serial bootloader and a WFI32E device in Wi-Fi serial bridge, it is possible to reflash the microcontroller "wirelessly" and then use telnet to interact with and debug the system remotely

  • This application also can make field-bus RS485-WiFi bridge with a RS485 transceiver implementing automatic direction control connected to the UART interface. That enable to build a "long" RS485 transmission line and debug it wirelessly or make simple extension without adding additional wires for a new sensor on the bus

Multiple TCP Connection

Mutliple TCP connection is supported when TCP Server is running on the WFI32E AP Device. WFI32E AP Device can connect to maximum eight WFI32 STA devices and create TCP connection to each STA devices. The UART-to-WiFi-TCP bridge on the WFI32E AP Device transmits all incoming TCP bytes from all of the sockets out of the WFI32E's UART module, and transmits all incoming UART bytes out of each TCP sockets.

If the Target transmit UART data to WFI32E AP Device, all of the WFI32 STA devices can receive the same data. In reverse, the target can receive the data from all of the WFI32 STA devices.

The number of socket is defined in uart_bridge.h

#define SERVER_PORT 47111
#define SOCKET_COUNT     8

Software requirement

The sample project has been created and tested with the following Software Development Tools:

  • MPLAB X IDE v6.00
  • MPLAB XC32 v3.01
  • MPLAB Harmony v3.6.4
    • mhc v3.8.2
    • csp v3.10.0
    • core v3.10.0
    • wireless_wifi v3.6.1
    • dev_packs v3.10.0
    • wireless_system_pic32mzw1_wfi32e01 v3.6.1
    • wolfssl v4.7.0
    • net v3.7.4
    • crypto v3.7.5
    • CMSIS-FreeRTOS v10.3.1

Download and install a serial terminal program like TeraTerm. Launch TeraTerm program and configure the serial ports mounted with: 115200 bps, 8 N 1

Hardware setup using the WFI32 Curiosity Board

WFI32E AP Device

  • J202 = VBUS
  • J301 = open
  • Computer connected to WFI32 Curiositiy board over USB POWER (J204) to power the board and observe the console logs
  • USB-to-UART cable between the computer and GPIO Header UART1 pins (Rx, GND, Tx) for the Transparent UART bridge

WFI32E Station Device

  • J202 = VBUS
  • J301 = open
  • Computer connected to WFI32 Curiositiy board over USB POWER (J204) to power the board and for the Transparent UART bridge
  • USB-to-UART cable between the computer and GPIO Header UART1 pins (Rx, GND, Tx) to observe the console logs

Hardware setup using the WFI32 IoT Board

  • Computer connected to WFI32 IoT board over USB (J200) to power the board and act as a USB Hub to debug/program the board, observe the console logs over a USB CDC and interact with the Transparent UART bridge over USB CDC

LED indicators

The on-board LEDs provides a visual indication on the application status.

LED Status Description
RED LED Blinking In Wi-Fi connection process
RED LED On/solid Wi-Fi station is connected to Wi-Fi AP
GREEN LED Blinking In TCP connection process, wait for UART message from the station
GREEN LED On/solid TCP UART Bridge established
RED LED Flickering Data sent to TCP (Wi-Fi)
GREEN LED Flickering Data sent to UART (CDC)

Try it using two WFI32E boards

  1. Clone/download the repo
  2. Open the uartbridge_ap project with MPLAB X IDE
  3. Build and program the code in the SoftAP board
  4. Open the uartbridge_sta project with MPLAB X IDE
  5. Build and program the code in the Station board
  6. Reset both boards
  7. Wait until the Transparent UART to Wi-Fi is established, observe the Red LED flash until the WLAN connection is established
  8. The Red LED become solid and the Green LED indicates that a TCP Client/Server connection has been established and data can be transported

  1. Exchange data from the console: type characters, send file

  1. Observe the LEDs. If data is sent in the direction of TCP (Wi-Fi), the Red LED flickers. At rest, the Red LED stays On. If data is sent in the direction of the UART (or USB CDC), the Green LED flickers. At rest, the Green LED stays On. If the Green LED starts flashing on a regular basis, the TCP connection has been interrupted. If the Red LED starts flashing on a regular basis, then the Wi-Fi connection has been interrupted. For the two last cases, the recommendation is to restart the firmware on both boards with the Reset/MCLR buttons.

Try it using one WFI32E board and a Computer

  1. Clone/download the repo
  2. Open the uartbridge_ap project with MPLAB X IDE
  3. Build and program the code in the SoftAP board
  4. Using your computer with WLAN adapter as a Wi-Fi Station, connect to DEMO_AP_SOFTAP (pwd: password)

  1. Use the tool Packet Sender to connect to 192.168.1.1 and send/receive TCP packets on the port 47111
  2. Send a file from the TCP server and observe the data received on Packet Sender

  1. Send a file from the TCP client and observe the data received on the TCP server console (WFI32E).

Try it using one WFI32E board and a Smartphone

  1. Clone/download the repo
  2. Open the uartbridge_ap project with MPLAB X IDE
  3. Build and program the code in the SoftAP board
  4. Using your smartphone as a Wi-Fi Station, connect to DEMO_AP_SOFTAP (pwd: password)
  5. Use the Smartphone App called TCP Telnet Terminal (Google Play, App Store) to connect to 192.168.1.1 and send/receive TCP packets on the port 47111

  1. Send simple text message on both directions

pic32mzw1_uart_wifi_bridge's People

Contributors

gd91 avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

eds53323

pic32mzw1_uart_wifi_bridge's Issues

Read and Write UART2 on WFI32IOT board

I'm trying to read/write to UART2 on the WFI32iot board. My understanding is that UART2 is connected to the Mikrobus header on the board.

I saw the following calls in initialization.c, so I'm thinking that UART2 is initialized:
UART2_Initialize();
sysObj.drvUsart0 = DRV_USART_Initialize(DRV_USART_INDEX_0, (SYS_MODULE_INIT *)&drvUsart0InitData);

When I try to call UART2_Read/Write or DRV_USART_Open --> DRV_USART_WriteBuffer, both methods return success for write, but nothing is coming out from the RX/TX lines on the Mikrobus port. I hooked up a logic analyzer to those pins, and I don't see any signals either.

Any thoughts on why this is the case? Perhaps UART2 pins are not connected on the WFI32iot board?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.