Skip to content

Add OTA API and HTTP Example Guide #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions source/API_Documents/OTA/Header OTA.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
Header OTA
==========

.. contents::
:local:
:depth: 2

**OTA Header**
--------------

**Description**
~~~~~~~~~~~~~~~

A header file for OTA API.

**Syntax**
~~~~~~~~~~

NA

**Members**
~~~~~~~~~~~

+-----------------------------------+----------------------------------+
| **Public Constructors** | |
+===================================+==================================+
| NA | NA |
| | |
| | |
+-----------------------------------+----------------------------------+
| **Public Methods** | |
+-----------------------------------+----------------------------------+
| start_OTA_threads | To begin threading tasks for OTA |
| | firmware update. |
+-----------------------------------+----------------------------------+

**start_OTA_threads**
---------------------

**Description**
~~~~~~~~~~~~~~~

To begin threading tasks for OTA firmware update.

**Syntax**
~~~~~~~~~~

.. code-block:: c++

void start_OTA_threads();

**Parameters**
~~~~~~~~~~~~~~

NA

**Returns**
~~~~~~~~~~~

NA

**Example Code**
~~~~~~~~~~~~~~~~

Example: `OTA <https://github.com/ambiot/ambpro2_arduino/blob/dev/Arduino_package/hardware/libraries/OTA/examples/OTA/OTA.ino>`_

.. note :: “ota_thread.h” must be included to use the function.
7 changes: 7 additions & 0 deletions source/API_Documents/OTA/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
OTA
===

.. toctree::
:maxdepth: 1

Header OTA
1 change: 1 addition & 0 deletions source/API_Documents/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ API Documents
Multimedia/index
NeuralNetwork/index
NTPClient/index
OTA/index
USB/index
Watchdog/index
WiFi/index
Expand Down
46 changes: 46 additions & 0 deletions source/Example_Guides/HTTP/HTTP Post Image and MP4.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
HTTP Post Image and MP4
=======================

.. contents::
:local:
:depth: 2

Materials
---------

- `AMB82-mini <https://www.amebaiot.com/en/where-to-buy-link/#buy_amb82_mini>`_ x 1

- PushButton x1

- 220 ohm resistor x1

Example
-------

In this example, we are doing a Post request with image and recorded audio file together to LLM Server. This example does not contain integration to the LLM server but integration to the HTTP server.

Then open “File” -> “Examples” -> “AmebaHttp” -> “Capture_Image_HTTP_Post_Image_Llava_Server”

|image01|

Connect the pushbutton and resistor to AMB82 Mini as shown below.

|image02|

Compile and run the example.

Set up the HTTP server by locating the python script called whisper_server_test_2_endpoints.py. Go to command prompt and go to the src folder. Execute this command python3 whisper_server_test_2_endpoints.py.

Please note that this server can only be run on Linux OS. Mac OS and Windows have not been supported yet.

Press button for 2s when you wish to take a snapshot and speak into the mic for the prompt to ask the Visual Language Model (VLM).

If the HTTP Post image and audio file is successful, the image and audio file will be saved at the location where this script is being run at.

.. |image01| image:: ../../_static/Example_Guides/HTTP/HTTP_Post_Image_and_MP4/image01.png
:width: 1032 px
:height: 645 px

.. |image02| image:: ../../_static/Example_Guides/HTTP/HTTP_Post_Image_and_MP4/image02.png
:width: 988 px
:height: 802 px
66 changes: 66 additions & 0 deletions source/Example_Guides/HTTP/HTTP Post MP4.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
HTTP Post MP4
=============

.. contents::
:local:
:depth: 2

Materials
---------

- `AMB82-mini <https://www.amebaiot.com/en/where-to-buy-link/#buy_amb82_mini>`_ x 1

- PushButton x1

- 220 ohm resistor x1

Example
-------

These examples illustrate how to send HTTP Post request of MP4 audio file to a HTTP server.

This guide will be relevant to 2 examples:

1) HTTP_Post_MP4_Whisper_Server

2) RecordMP4_HTTP_Post_Whisper_Server

The difference between these 2 examples is that for HTTP_Post_MP4_Whisper_Server.ino, one is expected to have an MP4 file already saved inside the SD card. Whereas for the RecordMP4_HTTP_Post_Whisper_Server.ino, it is not necessary to have a MP4 file inside the SD card.

This is the block diagram for the example flow.

|image01|

Connect the pushbutton and resistor to AMB82 Mini as shown below.

|image02|

Open “File”-> “Examples” -> “AmebaHTTP” -> “HTTP_Post_MP4_Whisper_Server” OR “RecordMP4_HTTP_Post_Whisper_Server”.

|image03|

Compile and run the code.

Set up the http server by locating the python script called “whisper_llm_server.py” in src folder. Go to command prompt and go to the src folder and execute this command: python3 whisper_llm_server.py. Follow the readme in the python script.

Press the push button for 2s to trigger the recording. Speak into the microphone to ask the AI. This should be the expected output on the terminal that was running the python script. Please note that if you are
to use a more powerful model such as MediaTek 7B model, you will need a
PC with a powerful GPU to test. Purely CPU will not be able to run that
model.

Please note that this server can only be run on Linux OS. Mac OS and Windows have not been supported yet.

|image04|

.. |image01| image:: ../../_static/Example_Guides/HTTP/HTTP_Post_MP4/image01.png
:width: 722 px
:height: 255 px
.. |image02| image:: ../../_static/Example_Guides/HTTP/HTTP_Post_MP4/image02.png
:width: 988 px
:height: 802 px
.. |image03| image:: ../../_static/Example_Guides/HTTP/HTTP_Post_MP4/image03.png
:width: 1032 px
:height: 645 px
.. |image04| image:: ../../_static/Example_Guides/HTTP/HTTP_Post_MP4/image04.png
:width: 1157 px
:height: 234 px
58 changes: 58 additions & 0 deletions source/Example_Guides/HTTP/Retrieve HTTP webs.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
Retrieve HTTP webs
==================

.. contents::
:local:
:depth: 2

Materials
---------

- `AMB82-mini <https://www.amebaiot.com/en/where-to-buy-link/#buy_amb82_mini>`_ x 1

Example
-------

| In this example, the HttpClient library is used to retrieve a webpage using the HTTP protocol.
| First, make sure that the correct Ameba development board is selected in “Tools” -> “Board”.

Then open “File” -> “Examples” -> “AmebaHttp” -> “RetrieveHttpWebs”.

|image01|

In the sample code, modify the highlighted section to enter the information required (ssid, password, key index) to connect to your WiFi network.

|image02|

Upload the code and press the reset button on Ameba once the upload is finished. Open the serial monitor in the Arduino IDE and you can see the information retrieved from the website.

|image03|

Code Reference
--------------

| Use WiFi.begin() to establish WiFi connection:
| https://www.arduino.cc/en/Reference/WiFiBegin
| To get the information of a WiFi connection:
| Use WiFi.SSID() to get SSID of the current connected network.
| https://www.arduino.cc/en/Reference/WiFiSSID
| Use WiFi.RSSI() to get the signal strength of the connection.
| https://www.arduino.cc/en/Reference/WiFiRSSI
| Use WiFi.localIP() to get the IP address of Ameba.
| https://www.arduino.cc/en/Reference/WiFiLocalIP
| Use WiFiClient to create a client to handle the WiFi connection.
| https://www.arduino.cc/en/Reference/WiFiClient
| Use HTTPClient to create a client to handle the HTTP connection.

Use http.get() to send a GET request to the website.


.. |image01| image:: ../../_static/Example_Guides/HTTP/Retrieve_HTTP_webs/image01.png
:width: 602 px
:height: 833 px
.. |image02| image:: ../../_static/Example_Guides/HTTP/Retrieve_HTTP_webs/image02.png
:width: 568 px
:height: 565 px
.. |image03| image:: ../../_static/Example_Guides/HTTP/Retrieve_HTTP_webs/image03.png
:width: 752 px
:height: 496 px
Loading
Loading