Skip to content

Commit c883e73

Browse files
authored
Add OTA - Ameba Over-the-Air Firmware Update.rst (#2)
- Add OTA - Ameba Over-the-Air Firmware Update.rst - Add image for OTA docs in static folder
1 parent f3fcc1b commit c883e73

File tree

18 files changed

+191
-0
lines changed

18 files changed

+191
-0
lines changed
Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
Ameba Over-the-Air Firmware Update
2+
==================================
3+
4+
.. contents::
5+
:local:
6+
:depth: 2
7+
8+
Materials
9+
---------
10+
11+
- `AMB82-mini <https://www.amebaiot.com/en/where-to-buy-link/#buy_amb82_mini>`_ x 1
12+
- Set up of Web UI in a PC
13+
14+
Example
15+
-------
16+
17+
In this example, we use a web UI to upload firmware to one or more AMB82 Mini.
18+
19+
For the instructions to set up web UI for AmebaPro2 OTA: Web UI, please click into the link below and perform the steps as shown in the README.md. [https://github.com/Ameba-AioT/ameba-OTA-UI]
20+
21+
If Ameba OTA Web UI is set up successfully in your PC, you will see the webpage on [http://localhost:3000/], figure below shows the rendering of webpage with no device connected:
22+
23+
|image01|
24+
25+
To begin, open the OTA example in Arduino IDE. “File” -> “Examples” -> “AmebaOTA” -> “OTA”.
26+
27+
|image02|
28+
29+
Open any text editor and open the file ota_drv.c. Edit the port and server of your HTTP server. Usually, you will only need to change the server IP address to your PC’s IP address. Do not change the port here unless you change the port in the Web UI too.
30+
31+
|image03|
32+
33+
Before compiling and upload the example, go to Arduino IDE:
34+
35+
1. Set NN Model Load From SD Card. “Tools” -> “NN Model Load From” -> “SD Card”
36+
37+
|image04|
38+
39+
2. Enable the OTA mode. “Tools” -> “OTA Mode” -> “Enable”
40+
41+
|image05|
42+
43+
3. Modify the SSID and password according to your AP
44+
45+
Now, compile and upload this example into each and every board that you have. It can be one board or multiple boards (we will be using two AMB82 Mini boards in this example guide).
46+
47+
This set up must be done at least once to allow the OTA thread API to be called for the first time. For subsequent firmware updates, as long as “ota_thread.h” is included and “start_ota_threads” API is called in the setup function, you do not need to re-upload the code manually.
48+
49+
Once uploaded, press reset button and get the IP address of the individual AMB82 Mini on serial monitor.
50+
51+
Board 1 IP address: 192.168.3.26
52+
53+
|image06|
54+
55+
Board 2 IP address: 192.168.3.65
56+
57+
|image07|
58+
59+
Then, go to Ameba OTA Web UI [http://localhost:3000/] to view the connected device(s).
60+
61+
|image08|
62+
63+
If you can see the IP address(es) of your AMB82 Mini board(s) on the OTA webpage, it shows that the connection is successful.
64+
65+
For the steps below, you may disconnect AMB82 Mini from your PC and power up the board with any stable 5V DC power source. The overall connection map of this example guide is shown in the figure below.
66+
67+
|image09|
68+
69+
In this tutorial, we will be uploading a NTPClient sketch via OTA. Open the NTPClient example. “File”-> “Examples” -> “NTPClient” -> ”Basic”. Include the header file “ota_thread.h” and at the end of setup function, add in the API “start_OTA_threads();”. Also modify the SSID and password according to your AP. Your PC and AMB82 Mini should be connecting to the same local network. Refer to the picture below for the modified NTPClient sketch.
70+
71+
|image10|
72+
73+
Before compiling, remember to set NN Model to load from SD card and enable OTA mode.
74+
75+
Compile the modified NTPClient sketch, DO NOT upload after compilation.
76+
77+
Priority matters: Kindly take note that AMB82 Mini will only boot with the latest compiled firmware.
78+
79+
Once compilation is done, look for ota.bin file in C:\\Users\\<username>\\AppData\\Local\\Arduino15\\packages\\realtek\\tools\\ameba_pro2_tools\\1.3.7
80+
81+
Upload ota.bin (or renamed ota.bin) to the webpage UI for OTA transfer to AMB82, as shown in the figure below:
82+
83+
|image11|
84+
85+
Once uploaded, select the device(s) to perform OTA transfer:
86+
87+
|image12|
88+
89+
Click Start OTA to begin OTA transfer. You will see the change of OTA state while the firmware is being updated on the board(s), as shown in the figure below.
90+
91+
|image13|
92+
93+
The board will automatically reboot with the OTA transferred firmware (i.e. modified NTPClient in this example) once download progress is completed.
94+
95+
You will see the output generated on serial monitor after reboot.
96+
97+
Board 1:
98+
99+
|image14|
100+
101+
Board 2:
102+
103+
|image15|
104+
105+
.. |image01| image:: ../../_static/Example_Guides/OTA/Ameba_Over-the-Air_Firmware_Update/image01.png
106+
:width: 602 px
107+
:height: 348 px
108+
.. |image02| image:: ../../_static/Example_Guides/OTA/Ameba_Over-the-Air_Firmware_Update/image02.png
109+
:width: 601 px
110+
:height: 533 px
111+
.. |image03| image:: ../../_static/Example_Guides/OTA/Ameba_Over-the-Air_Firmware_Update/image03.png
112+
:width: 600 px
113+
:height: 467 px
114+
.. |image04| image:: ../../_static/Example_Guides/OTA/Ameba_Over-the-Air_Firmware_Update/image04.png
115+
:width: 654 px
116+
:height: 661 px
117+
.. |image05| image:: ../../_static/Example_Guides/OTA/Ameba_Over-the-Air_Firmware_Update/image05.png
118+
:width: 662 px
119+
:height: 662 px
120+
.. |image06| image:: ../../_static/Example_Guides/OTA/Ameba_Over-the-Air_Firmware_Update/image06.png
121+
:width: 370 px
122+
:height: 254 px
123+
.. |image07| image:: ../../_static/Example_Guides/OTA/Ameba_Over-the-Air_Firmware_Update/image07.png
124+
:width: 371 px
125+
:height: 256 px
126+
.. |image08| image:: ../../_static/Example_Guides/OTA/Ameba_Over-the-Air_Firmware_Update/image08.png
127+
:width: 603 px
128+
:height: 336 px
129+
.. |image09| image:: ../../_static/Example_Guides/OTA/Ameba_Over-the-Air_Firmware_Update/image09.png
130+
:width: 896 px
131+
:height: 504 px
132+
.. |image10| image:: ../../_static/Example_Guides/OTA/Ameba_Over-the-Air_Firmware_Update/image10.png
133+
:width: 602 px
134+
:height: 373 px
135+
.. |image11| image:: ../../_static/Example_Guides/OTA/Ameba_Over-the-Air_Firmware_Update/image11.png
136+
:width: 519 px
137+
:height: 518 px
138+
.. |image12| image:: ../../_static/Example_Guides/OTA/Ameba_Over-the-Air_Firmware_Update/image12.png
139+
:width: 969 px
140+
:height: 590 px
141+
.. |image13| image:: ../../_static/Example_Guides/OTA/Ameba_Over-the-Air_Firmware_Update/image13.png
142+
:width: 755 px
143+
:height: 449 px
144+
.. |image14| image:: ../../_static/Example_Guides/OTA/Ameba_Over-the-Air_Firmware_Update/image14.png
145+
:width: 632 px
146+
:height: 596 px
147+
.. |image15| image:: ../../_static/Example_Guides/OTA/Ameba_Over-the-Air_Firmware_Update/image15.png
148+
:width: 526 px
149+
:height: 560 px
150+
151+
Code Reference
152+
--------------
153+
154+
Multithreading:
155+
156+
Two threads are written in start_OTA_threads() to ensure successful OTA update.
157+
158+
Thread 1: For the purpose of connectivity check, the OTA state is sent to the server from AMB82 Mini board. Once received, the OTA state of the board will be shown on the Web UI.
159+
160+
.. code-block:: c++
161+
162+
thread1_id = os_thread_create_arduino(thread1_task, NULL, priority1, stack_size1);
163+
164+
// First thread is to do keep alive connectivity check (post requests every 5s)
165+
if (thread1_id) {
166+
Serial.println("[OTA] Keep-alive connectivity thread created success-fully.");
167+
} else {
168+
Serial.println("[OTA] Failed to create keep-alive connectivity thread.");
169+
}
170+
171+
172+
Thread 2: To listen for the OTA begin signal from server, once “start_ota” signal is received, AMB82 Mini will request for the firmware to be downloaded via OTA.
173+
174+
.. code-block:: c++
175+
176+
thread2_id = os_thread_create_arduino(thread2_task, NULL, priority1, stack_size2);
177+
178+
// Second thread is to get the signal to start OTA process.
179+
if (thread2_id) {
180+
Serial.println("[OTA] Start OTA process thread created successfully.");
181+
} else {
182+
Serial.println("[OTA] Failed to create Start OTA process thread.");
183+
}

source/Example_Guides/OTA/index.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
OTA
2+
===
3+
4+
.. toctree::
5+
:maxdepth: 1
6+
7+
Ameba Over-the-Air Firmware Update

source/Example_Guides/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ Example Guides
66

77
Basic/index
88
Flash Memory/index
9+
OTA/index
910
USB/index
1011
Watchdog/index
Loading
Loading
Loading
Loading
Loading
Loading
Loading

0 commit comments

Comments
 (0)