Differences

This shows you the differences between two versions of the page.

Link to this comparison view

iothings:laboratoare:2022:lab10 [2024/05/16 08:36]
robert_ionut.alexa [Run as sudo]
iothings:laboratoare:2022:lab10 [2025/05/14 15:12] (current)
andreea.miu [Environment]
Line 10: Line 10:
 === Native Linux machine === === Native Linux machine ===
  
-You can go ahead to section [Run as sudo].+You can go ahead to section ​**[Compiling NuttX]**.
  
 === Windows setup === === Windows setup ===
Line 28: Line 28:
 Currently, the WSL subsystem does not provide native support for USB devices and you must use an open-source tool. Please refer to [[https://​learn.microsoft.com/​en-us/​windows/​wsl/​connect-usb | this ]] for further details. Currently, the WSL subsystem does not provide native support for USB devices and you must use an open-source tool. Please refer to [[https://​learn.microsoft.com/​en-us/​windows/​wsl/​connect-usb | this ]] for further details.
  
-==== Run as sudo ==== +==== Compiling NuttX ====
- +
-Running as non-root will require a few extra commands for configuration. +
- +
-Refer to [[https://​blog.espressif.com/​getting-started-with-esp32-and-nuttx-fd3e1a3d182c | this]] if you decide to continue as non-root.+
  
 Follow the steps below in order to get your Linux machine properly configured: Follow the steps below in order to get your Linux machine properly configured:
Line 42: Line 38:
   * compile the NuttX binary   * compile the NuttX binary
   * finally, flash the board   * finally, flash the board
 +
 +<note important>​It is strongly recommended to run all of the commands on your VM/Linux host as **sudo**. Running those commnads without sudo requires extra configuration steps. </​note>​
 +
  
 == Install dependencies == == Install dependencies ==
Line 54: Line 53:
  
 <​code>​ <​code>​
-curl https://​github.com/​espressif/​crosstool-NG/​releases/​download/​esp-12.2.0_20230208/​xtensa-esp32-elf-12.2.0_20230208-x86_64-linux-gnu.tar.xz ​tar -xz+wget https://​github.com/​espressif/​crosstool-NG/​releases/​download/​esp-12.2.0_20230208/​xtensa-esp32-elf-12.2.0_20230208-x86_64-linux-gnu.tar.xz 
 +tar -xf xtensa-esp32-elf-12.2.0_20230208-x86_64-linux-gnu.tar.xz
 mkdir /opt/xtensa mkdir /opt/xtensa
 mv xtensa-esp32-elf/​ /​opt/​xtensa/​ mv xtensa-esp32-elf/​ /​opt/​xtensa/​
Line 65: Line 65:
 <​code>​ <​code>​
 mkdir ~/​nuttxspace && cd ~/​nuttxspace mkdir ~/​nuttxspace && cd ~/​nuttxspace
-git clone https://​github.com/​apache/​incubator-nuttx.git nuttx +git clone --branch=nuttx-12.5.1 ​https://​github.com/​apache/​incubator-nuttx.git nuttx 
-git clone https://​github.com/​apache/​incubator-nuttx-apps.git apps+git clone --branch=nuttx-12.5.1 ​https://​github.com/​apache/​incubator-nuttx-apps.git apps
 </​code>​ </​code>​
  
Line 83: Line 83:
 {{ :​iothings:​laboratoare:​2022:​nuttx_download_mode.png |}} {{ :​iothings:​laboratoare:​2022:​nuttx_download_mode.png |}}
  
 +Use the following commands to install the necessary Python modules and configure the compile options needed for the WROVER module.
 <​code>​ <​code>​
 pip3 install esptool pip3 install esptool
Line 90: Line 91:
 </​code>​ </​code>​
  
-<​note>​The last line is specific to boards containing the WROVER module, such as the ESP32 Sparrow boards we use in the lab. Please note that if you're compiling for another hardware target, such as one containing the more popular WROOM modules, the last line needs to be changed to reflect that, e.g. //​./​tools/​configure.sh esp32-devkitc:​nsh// ​+<​note>​The last line is specific to boards containing the WROVER module, such as the ESP32 Sparrow boards we use in the lab. Please note that if you're compiling for another hardware target, such as one containing the more popular WROOM modules, the last line needs to be changed to reflect that, e.g. //​./​tools/​configure.sh esp32-devkitc:​nsh//​.  ​
 </​note>​ </​note>​
  
Line 107: Line 108:
 {{ :​iothings:​laboratoare:​2022:​nuttx_flash_log.png?​700 |}} {{ :​iothings:​laboratoare:​2022:​nuttx_flash_log.png?​700 |}}
  
-Finally, the boot log should look like this:+Finally, the boot log on the ESP32 board should look like this:
  
 {{ :​iothings:​laboratoare:​2022:​nuttx_boot_log.png?​700 |}} {{ :​iothings:​laboratoare:​2022:​nuttx_boot_log.png?​700 |}}
  
 +==== WiFi ====
 +
 +ESP32 boards incorporate an RF (Radio Frequency) module through which they can use Wi-Fi, Bluetooth and BLE (Bluetooth Low Energy). Since all three technologies operate at the 2.4GHz frequency, we cannot receive and send data at the same time on Wi-Fi and Bluetooth. To make this possible, time-division multiplexing is used.
 +
 +In Wi-Fi communication,​ a device can have one of the following roles:
 +
 +  * Router - defines a new network;
 +  * Access Point (AP) - a device that is part of a network, connects to the router, but is used to create subnets, e.g. a smartphone with the hotspot option configured;
 +  * Station (STA) - a simple device connected to the network.
 +
 +In the previous section, we finished our first compilation of the NuttX OS, using the default configuration for ESP32 WROVER boards with //nsh//, which includes the default terminal and minimal features. In NuttX, the ESP32 can run both as a station and as an access point (software access point - SoftAP - because communication management happens within the operating system, not in the hardware). Configurations like ''​esp32-wrover-kit:​wifi''​ allow the board to function only as a station, but there is also ''​esp32-devkitc:​sta_softap'',​ for example, which provides support for both station and SoftAP.
 +
 +In order to connect the ESP32 board to an existing Wi-Fi network identified using <​myssid>:<​mypassword>,​ use the commands below:
 +<​code>​
 +ifup wlan0
 +wapi psk wlan0 <​mypasswd>​ 3
 +wapi essid wlan0 <​myssid>​ 1
 +renew wlan0
 +</​code>​
 +
 +Because ''​wapi essid''​ only sets the network name internally, in order to connect to the network and obtain an IP address an explicit command is required - ''​renew wlan0''​.
 +
 +To configure ESP32 to run as a SoftAP (via the second available network interface - wlan1), a similar set of commands is needed:
 +<​code>​
 +ifup wlan1
 +dhcpd_start wlan1
 +wapi psk wlan1 <​mypasswd>​ 3
 +wapi essid wlan1 nuttxapp 1
 +</​code>​
 +
 +In this way, the ''​nuttxapp''​ network is created, also protected by WPA2 and CCMP, with the password <​mypasswd>​. ''​dhcpd_start''​ starts the ''​dhcpd''​ daemon, which will run a DHCP server and assign an IP to all connected devices.
 +
 +A more detailed description of the API exposed by WAPI (e.g., ''​wapi show wlan0''​),​ as well as how to connect to an unsecured network (open network), can be found [[https://​nuttx.apache.org/​docs/​latest/​applications/​wapi/​index.html|here]].
 +
 +Additionally,​ another useful command to investigate the status of network interfaces is ''​ifconfig'',​ similar to the one in Linux.
 +
 +==== Exercises ====
 +
 +To be able to run the exercises, you need to compile NuttX using ''​esp32-devkitc:​sta_softap'',​ for which you will need to manually enable a few other configs, listed below. In order to modify the initial configuration,​ use the ''​make menuconfig''​ command after configuring ESP32 as sta_softap, and before starting the compilation process.
 +
 +<note tip>
 +You can navigate through the ''​menuconfig''​ interface using the search option (''/''​ key).
 +</​note>​
 +
 +  * CONFIG_NET_ROUTE=y
 +  * CONFIG_NET_IPFORWARD=y
 +  * CONFIG_NET_NAT=y
 +  * CONFIG_SYSTEM_IPTABLES=y
 +
 +**1.** Connect the ESP32 to the university network and test with ''​ping 8.8.8.8''​ that you have internet access. Use the ''​wlan0''​ interface.
 +
 +<note tip>
 +If you are unable to connect to the univerrsity network, you can use the hotspot on your mobile phone. This will allow you to test connecting to both an unsecured network and a secured one (via WPA2).
 +</​note>​
 +
 +<note important>​
 +NuttX does not handle the SIGINT signal by default, and running the ping will cause your nsh console to crash. You can avoid this problem by enabling CONFIG_TTY_SIGINT.
 +</​note>​
 +
 +Run the ''​route''​ command and inspect its output. It will be relevant to exercise 3.
 +
 +
 +**2.** Configure the board to run in SoftAP mode and connect your laptop to the network to test. Use the ''​wlan1''​ interface. Run the ''​route''​ command again and notice how the routing table has changed.
  
-<​note>​**Assignment 1:** Modify and compile ​the NuttX OS kernel ​to toggle on and off an on-board LED. You can use the [[https://​embetronicx.com/​tutorials/​rtos/​nuttx/​blink-led-on-esp32-using-nuttx-rtos/​ | following tutorial]] ​to get started. </​note>​+**3.** After exercise 2, the laptop is connected ​to the ESP32, but has no internet access. You can test this from CMD (Windows)/terminal (Linux) using ''​ping 8.8.8.8''​. Next, follow the steps below to fix the internet access issue:
  
-<​note>​**Assignment 2:** Build driver for the LTR308 light sensor on the Sparrow ​ESP32 boardsUse [[https://​github.com/​robertalexa2000/​nuttx-esp32-docs/​blob/​main/​drivers/​sensors.md | this]] tutorial as a starting point.</​note>​+  - From ESP32 run the command ''​ping 8.8.8.8''​ again. Notice that you have no internet access. Configuring wlan1 as SoftAP has broken ​the routing table, as can be seen from the output of the ''​route''​ command. 
 +  - Set the default routing rule using the command ''​addroute default 192.168.0.1 wlan0''​. ​ESP32 is connected to the internet again, you can test using ''​ping''​. 
 +  - The last step involves adding a rule in iptables to apply NAT on each packet routed by ESP32''​iptables ​-t nat -A POSTROUTING -o wlan0 -j MASQUERADE''​. 
 +  - Test from your personal laptop using ping, and from your browser connect to ''​www.google.com''​.
  
 ==== References ==== ==== References ====
Line 123: Line 190:
   * [[https://​nuttx.apache.org/​docs/​latest/​platforms/​xtensa/​esp32/​index.html | Official NuttX ESP32 build tutorial]]   * [[https://​nuttx.apache.org/​docs/​latest/​platforms/​xtensa/​esp32/​index.html | Official NuttX ESP32 build tutorial]]
   * [[https://​blog.espressif.com/​getting-started-with-esp32-and-nuttx-fd3e1a3d182c | Sara Monteiro'​s tutorial]]   * [[https://​blog.espressif.com/​getting-started-with-esp32-and-nuttx-fd3e1a3d182c | Sara Monteiro'​s tutorial]]
 +  * [[https://​nuttx.incubator.apache.org/​docs/​12.3.0/​applications/​wapi/​index.html| WAPI (Wireless API)]]
 +  * [[https://​eadalabs.com/​esp32-nuttx-and-bridged-networking/​|Esp32,​ NuttX and bridged networking]] ​
  
  
iothings/laboratoare/2022/lab10.1715837816.txt.gz · Last modified: 2024/05/16 08:36 (external edit)
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0