[M467 | M487] Build a Web Server on a NuMaker IoT board using Mbed OS

Post Reply
morgandu
Posts: 45
Joined: 28 Apr 2017, 22:47

27 Sep 2023, 10:51

[For further inquiries, please e-mail to shchen2@nuvoton.com]
[Visit https://www.nuvoton.com/iot_startup for more IoT solutions]



This is a reference sample code to run a web server on NuMaker IoT board to toggle the LED on board. It builds on Mbed OS and NuMaker IoT boards that support Ethernet function, such as NuMaker-IoT-M487 and NuMaker-IoT-M467 boards.

Prerequisite
  • A NuMaker-IoT-M467 board
    • Other NuMaker-IoT boards with Ethernet are also possible but NuMaker-IoT-M467 will be used for this tutorial
    Picture1.png
    Picture1.png (80.29 KiB) Viewed 18831 times
  • A RJ-45 Ethernet Cable
    Picture2.png
    Picture2.png (42.83 KiB) Viewed 18831 times
  • Mbed Studio – the development tool

Create a Project
  • Run Mbed Studio
  • Log in your Mbed account if it asks
  • Click File
  • Click Import Program
Picture3.png
Picture3.png (63.47 KiB) Viewed 18831 times
Picture4.png
Picture4.png (57.64 KiB) Viewed 18831 times
  • Active program is “NuMaker-simple-httpd”
  • Use NuMaker-IoT-M467 as example
    • Select target on the pull down menu, use M467 as keyword to find “NuMaker-IoT-M467”, then select it. Or you can
    • Plug the Nu-Link2 USB on NuMaker-IoT-M467 to PC. Mbed Studio will detect it automatically and then select Yes when it ask you to set the device as active.
Picture5.png
Picture5.png (88.29 KiB) Viewed 18831 times

View and Configure Code
  • Click source and then click main.cpp to show the source code
  • LED1 is LEDR on NuMaker-IoT-M467.
  • STATIC_IP is 0 to get IP address via DHCP, 1 to use IP address defined in code.
  • All browser requests will direct to request_handler() function
  • If your test environment has DHCP server, left the STATIC_IP to 0.
  • If the LAN cable connects to a Windows PC or laptop, because of no DHCP server, set STATIC_IP to 1 to use the IP address defined in the sample code.
  • The tutorial set STATIC_IP to 1.
Picture6.png
Picture6.png (96.09 KiB) Viewed 18831 times


Build Code
  • Click hammer to build code
    Picture7.png
    Picture7.png (101.69 KiB) Viewed 18831 times
  • After build finish, you get the firmware image file NuMaker-simple-httpd.bin in the folder
    • Windows
      C:\Users\YOUR-ACCOUNT\Mbed Programs\NuMaker-simple-httpd\BUILD\NUMAKER_IOT_M467\ARMC6
    • Linux
      ~/Mbed Programs/NuMaker-simple-httpd/BUILD/NUMAKER_IOT_M467/ARMC6

Program Firmware to Board
  • Make sure that no.1 & 2 are ON and no.3 & 4 are OFF of ICESW2 on Nu-Link2-ME
    Picture9.png
    Picture9.png (38.12 KiB) Viewed 18831 times
  • Plug in USB cable to PC
  • A NuMicro MCU drive appears on PC
  • Copy NuMaker-simple-httpd.bin to NuMicro MCU drive to program firmware. Or click “Connect” icon to download firmware and run.
Picture8.png
Picture8.png (93.54 KiB) Viewed 18831 times
Open the Terminal
  • Mbed Studio automatically open a terminal when a Mbed Enabled board detected.
  • Or you can run a terminal tool to open Nu-Link2-ME virtual COM port
  • Select baud rate to 115200
Picture10.png
Picture10.png (86.47 KiB) Viewed 18831 times


Run
  • Uses a Ethernet cable to connects a Windows PC or laptop) and a NuMaker-IoT-M467 board
  • Press RESET button on NuMaker-IoT-M467 to restart the firmware
    Picture13a.png
    Picture13a.png (75.28 KiB) Viewed 18827 times
  • The terminal shows the running messages
  • Initialize Ethernet
  • Web server is listening at http://169.254.108.2:8080
Picture11.png
Picture11.png (29.54 KiB) Viewed 18831 times

  • Open a browser on PC
  • Enter the URL http://169.254.108.2:8080
  • Click Toggle LED button then the LEDR on NuMaker-IoT-M467 will toggle once.
  • So web server is working to toggle LED on NuMaker board through a browser on PC.
Picture12.png
Picture12.png (8.69 KiB) Viewed 18831 times
Picture13b.png
Picture13b.png (75.8 KiB) Viewed 18827 times
Enjoy it. ;)

Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 85 guests