[M467 | M487] Build a Web Server on a NuMaker IoT board using Mbed OS
Posted: 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
Create a Project
View and Configure Code
Build Code
Program Firmware to Board
Run
![Wink ;)](./images/smilies/icon_e_wink.gif)
[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
- A RJ-45 Ethernet Cable
- Mbed Studio – the development tool
- Register an Mbed OS account to use Mbed tools for free https://os.mbed.com
- Download Mbed Studio and install it https://os.mbed.com/studio
Create a Project
- Run Mbed Studio
- Log in your Mbed account if it asks
- Click File
- Click Import Program
- Fill the example link to URL https://github.com/morgan-du/NuMaker-simple-httpd
- Click Add Program
- 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.
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.
Build Code
- Click hammer to build code
- 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
- Windows
Program Firmware to Board
- Make sure that no.1 & 2 are ON and no.3 & 4 are OFF of ICESW2 on Nu-Link2-ME
- 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.
- 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
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
- The terminal shows the running messages
- Initialize Ethernet
- Web server is listening at http://169.254.108.2:8080
- 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.
![Wink ;)](./images/smilies/icon_e_wink.gif)