Skip to content

Add HTTP File Server and MP4 Example guide and update AmebaFatFS API #32

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 3 commits into from
Mar 3, 2025
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,15 @@ Open a file. The file will be created if it does not already exist.
.. code-block:: c++

File open(const String& path);
File open(const String &path, int fileType);
File open(const char* path);
File open(const char *path, int fileType);

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

path: The full path of the file to open. Expressed as a String class object or a pointer to a char array.
fileType: The macro of the file type defined in AmebaFatFSFile.h to support different opening steps for different types of file.

**Returns**
~~~~~~~~~~~
Expand Down
79 changes: 79 additions & 0 deletions source/amebapro2/API_Documents/FileSystem/Class File.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ A class for data manipulation of files in a file system.
+---------------------------+------------------------------------------+
| File::convertMp3ToArray | Convert MP3 file to MP3data and MP3size. |
+---------------------------+------------------------------------------+
| File::setMp3DigitalVol | Control the digital gain of DAC. |
+---------------------------+------------------------------------------+
| File::playmp3 | Execute convertMp3TArray. |
+---------------------------+------------------------------------------+

**File::File**
--------------
Expand All @@ -74,11 +78,13 @@ Constructs a File object.

File::File(void);
File::File(const char* filename);
File::File(const char *filename, int fileType);

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

filename: pointer to a char array containing the path of the file to open.
fileType: The macro of the file type defined in AmebaFatFSFile.h to support different opening steps for different types of file.

**Returns**
~~~~~~~~~~~
Expand Down Expand Up @@ -106,6 +112,7 @@ Open a file from the file system.
.. code-block:: c++

bool open(const char* filename);
bool open(const char *filename, int fileType);

**Parameters**
~~~~~~~~~~~~~~
Expand Down Expand Up @@ -521,3 +528,75 @@ This function convert MP3 file into character array containing the MP3data witho
NA

.. note :: "AmebaFatFSFile.h" must be included to use the class function.

**File::setMp3DigitalVol**
--------------------------

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

Control the digital gain of DAC.

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

.. code-block:: c++

void setMp3DigitalVol(uint8_t digitalVol);

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

digitalVol: output digital volume

.. note::
Every Step is 0.375dB.

| 0xAF: 0dB.
| 0xAE: -0.375dB.
| ...
| 0x00: -65.625dB.

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

NA

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

NA

.. note :: "AmebaFatFSFile.h" must be included to use the class function.

**File::playMp3**
-----------------

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

Execute convertMp3TArray.

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

.. code-block:: c++

void playMp3(void);

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

NA

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

NA

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

NA

.. note :: "AmebaFatFSFile.h" must be included to use the class function.
134 changes: 134 additions & 0 deletions source/amebapro2/API_Documents/HTTP/Class Httpfs.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
Class Httpfs
============

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

**Httpfs Class**
-----------------

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

A class used HTTP File Server.

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

.. code-block:: c++

class Httpfs

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

+-----------------------------------+-----------------------------------+
| **Public Constructors** | |
+===================================+===================================+
| Httpfs::Httpfs | Constructs a Httpfs object. |
+-----------------------------------+-----------------------------------+
| **Public Methods** |
+-----------------------------------+-----------------------------------+
| Httpfs::begin | Initializes the HTTP file server, |
| | set parameter, response callback |
| | function of the file server. |
+-----------------------------------+-----------------------------------+
| Httpfs::mp4DirectoryInit | Initializes the directory to save |
| | MP4 recordings on SD card. |
+-----------------------------------+-----------------------------------+
| Httpfs::end | Deinitializes the HTTP file |
| | server. |
+-----------------------------------+-----------------------------------+

**Httpfs::begin**
-----------------

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

Initializes the HTTP file server, set parameter, response callback function of the file server.

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

.. code-block:: c++

void begin(void);

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

NA

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

NA

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

Example: `Httpfs_mp4 <https://github.com/Ameba-AIoT/ameba-arduino-pro2/blob/dev/Arduino_package/hardware/libraries/Http/examples/Httpfs_mp4/Httpfs_mp4.ino>`_

**Httpfs::mp4DirectoryInit**
----------------------------

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

Initializes the directory to save MP4 recordings on SD card.

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

.. code-block:: c++

void mp4DirectoryInit(void);

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

NA

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

NA

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

Example: `Httpfs_mp4 <https://github.com/Ameba-AIoT/ameba-arduino-pro2/blob/dev/Arduino_package/hardware/libraries/Http/examples/Httpfs_mp4/Httpfs_mp4.ino>`_

**Httpfs::end**
---------------

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

Deinitializes the HTTP file server.

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

.. code-block:: c++

void end(void);

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

NA

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

NA

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

Example: `Httpfs_mp4 <https://github.com/Ameba-AIoT/ameba-arduino-pro2/blob/dev/Arduino_package/hardware/libraries/Http/examples/Httpfs_mp4/Httpfs_mp4.ino>`_


7 changes: 7 additions & 0 deletions source/amebapro2/API_Documents/HTTP/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
HTTP
====

.. toctree::
:maxdepth: 1

Class Httpfs
1 change: 1 addition & 0 deletions source/amebapro2/API_Documents/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ API Documents
FlashMemory/index
GPIO/index
Gtimer/index
HTTP/index
Multimedia/index
NeuralNetwork/index
NTPClient/index
Expand Down
58 changes: 58 additions & 0 deletions source/amebapro2/Example_Guides/HTTP/HTTP File Server and MP4.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
HTTP File Server and MP4
========================

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

Materials
---------

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

- MicroSD card x1

Example
-------

In this example, we will use AmebaPro2 development board to establish a file server for mp4 recordings access.

Open “File” -> “Examples” -> “AmebaHttp” -> “Http_fs_mp4”.

|image01|

In the highlighted section, kindly modify it according to your WiFi SSID and password.

|image02|

You may also change the mp4 recording duration (in seconds) and filecount. Please do not change the filename ("folder"/"file").

|image03|

Then, compile and upload the code to AMB82 Mini.

.. note :: Kindly insert SD card before pressing the reset button

Open the serial monitor to view the logs. Please copy down the IP address and paste it on a web browser to view the file server page created.

|image04|

You may follow the instruction shown to download the mp4 recordings from AMB82 Mini over HTTP.

.. note :: Kindly refresh the page to view the latest update on the file server

.. |image01| image:: ../../../_static/amebapro2/Example_Guides/HTTP/HTTP_FS_MP4/image01.png
:width: 799 px
:height: 812 px

.. |image02| image:: ../../../_static/amebapro2/Example_Guides/HTTP/HTTP_FS_MP4/image02.png
:width: 879 px
:height: 332 px

.. |image03| image:: ../../../_static/amebapro2/Example_Guides/HTTP/HTTP_FS_MP4/image03.png
:width: 803 px
:height: 224 px

.. |image04| image:: ../../../_static/amebapro2/Example_Guides/HTTP/HTTP_FS_MP4/image04.png
:width: 609 px
:height: 261 px
1 change: 1 addition & 0 deletions source/amebapro2/Example_Guides/HTTP/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ HTTP
.. toctree::
:maxdepth: 1

HTTP File Server and MP4
HTTP Post Image and MP4
HTTP Post MP4
Retrieve HTTP webs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ Kindly refer to the list of objects below recognized by the default YOLO model,
{78, "hair dryer" },
{79, "toothbrush" }``


.. |image01| image:: ../../../_static/amebapro2/Example_Guides/Neural_Network/Neural_Network_-_Object_Detection_Image/image01.png
:width: 1114 px
:height: 963 px
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,3 @@ Resources
.. |image_3rd_party| image:: ../../../_static/3rd_party_logo.png
:scale: 10%





Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,3 @@ Resources
.. |image_3rd_party| image:: ../../../_static/3rd_party_logo.png
:scale: 10%