Demo LED Matrix
Note: This app is still under development.
Control LED Matrix display via a web app created with dynamic pages.
- SDK directory:
apps/demo/led_matrix
- Zentri App Store:
ZENTRI-LEDMATRIX
API Features Demonstrated
Platforms
This app works on:
- AMW004 - Zentri Mackerel evaluation board. See Connecting a Zentri AMW004 to a Zentri ASG001 Backpack
- AMW106 - Zentri Moray evaluation board
Requirements and Prerequisites
Requires a ZentriOS evaluation board and an 8x8 LED matrix display, such as provided with the Zentri ASG001 Monitor Backpack.
Resources
The file settings.ini is used to initialize the device. This is packaged with the .zap
file downloaded to the device.
A root html file, led_matrix/index.html
, is served by the ZentriOS HTTP Server.
Resources are downloaded to device flash in the app download process.
Description
The app uses a web interface with dynamic HTTP pages to control and monitor an 8x8 LED Matrix display.
Instructions for Use
Open a ZentriOS serial terminal to the device. See Getting Started, Opening a ZentriOS Terminal.
This app assumes your ZentriOS device is set up with the credentials to join your local network. If you have not already set up network credentials, on the ZentriOS terminal, run the commands:
network_up -s
save
See the Wi-Fi Command API documentation for network_up and save.
Build, download and run the app.
After the app has joined the network, it displays a message:
> Starting 8x8 LED Matrix Demo
From your browser, enter the URL: http://ledmatrix.local/ to control the display
Note the slash at the end of http://ledmatrix.local/
.
Connect a WLAN client (smartphone/PC/tablet) to the same network as the ZentriOS device and open a web browser.
The client web browser must support HTML5 slider controls for the web page to appear as intended.
From your browser, enter the URL: http://ledmatrix.local/
to control the display.
If your client platform doesn't support mDNS, you can view the page by entering the device IP address, followed by a slash, e.g.
http://192.168.6.7/
To see the device IP address, at the ZentriOS terminal enter the following command:
get network.ip
The web page displayed is similar to the following:
Without using the demonstration web page, you can control the LED matrix array with GET requests to the dynamic page URLs.
For example:
http://ledmatrix.local/led_matrix/update/text?data=Fred
changes the scrolling text to 'Fred'http://ledmatrix.local/led_matrix/update/blink?data=2
starts it blinking according to the blink rate defined valueshttp://ledmatrix.local/led_matrix/update/brightness?data=0
minimises the brightnesshttp://ledmatrix.local/led_matrix/update/brightness?data=15
maximises the brightnesshttp://ledmatrix.local/led_matrix/update/scroll?data=10
scrolls the text at high speed. Do not set below 10.http://ledmatrix.local/led_matrix/update/scroll?data=500
scrolls the text very slowly.http://ledmatrix.local/led_matrix/retrieve/all
displays the current values of text, blink rate, scroll rate and brightness.
Implementation
The HTTP Server macro calls set up URLs with associated callback processor functions:
HTTP_SERVER_DYNAMIC_PAGES_START
HTTP_SERVER_DYNAMIC_PAGE("/led_matrix/update/text", update_text_processor),
HTTP_SERVER_DYNAMIC_PAGE("/led_matrix/update/blink", update_blink_processor),
HTTP_SERVER_DYNAMIC_PAGE("/led_matrix/update/brightness", update_brightness_processor),
HTTP_SERVER_DYNAMIC_PAGE("/led_matrix/update/scroll", update_scroll_processor),
HTTP_SERVER_DYNAMIC_PAGE("/led_matrix/retrieve/all", retrieve_all_processor),
HTTP_SERVER_DYNAMIC_PAGES_END
zn_app_init
- zn_load_app_settings initializes the app settings from settings.ini
- led_matrix8x8_init initializes the LED Matrix array.
- led_matrix8x8_set_text sets the LED Matrix text.
- zn_network_restart brings the network down and back up to start the HTTP Server and mDNS.
zn_app_deinit
- led_matrix8x8_deinit deallocates memory used for the LED Matrix array when the app exits.
update_text_processor
- This callback processes a
/led_matrix/update/text?data=<value>
GET request. - zn_hs_get_param gets the
data
parameter structure. - led_matrix8x8_set_text sets the LED Matrix array text to the value of the parameter
- zn_hs_write_reply_header completes the GET request, with no content returned.
update_blink_processor
- This callback processes a
/led_matrix/update/blink?data=<value>
GET request. - zn_hs_get_param gets the
data
parameter structure. - led_matrix8x8_set_blink_rate sets the LED Matrix array blink rate to the value of the parameter
- zn_hs_write_reply_header completes the GET request, with no content returned.
update_brightness_processor
- This callback processes a
/led_matrix/update/brightness?data=<value>
GET request. - zn_hs_get_param gets the
data
parameter structure. - led_matrix8x8_set_brightness sets the LED Matrix array brightness to the value of the parameter
- zn_hs_write_reply_header completes the GET request, with no content returned.
update_scroll_rate
- This callback processes a
/led_matrix/update/scroll?data=<value>
GET request. - zn_hs_get_param gets the
data
parameter structure. - led_matrix8x8_set_scroll_rate sets the LED Matrix array scroll rate to the value of the parameter
- zn_hs_write_reply_header completes the GET request, with no content returned.
retrieve_all_processor
- This callback processes a
/led_matrix/retrieve/all
GET request. - led_matrix8x8_get_context gets the LED matrix context structure containing the values of settings.
- The app formats the settings into a json string, with all but the message text, closing quotation mark and brace.
- zn_hs_write_reply_header specifies an
application/json
mime type. - Calls to zn_hs_write_chunked_data send
- the first formatted part of the json response
- then the message text
- then the closing quotation mark and brace.
The index.html
page JavaScript sends GET requests with asynchronous XMLHttpRequests, and processes the json response to /led_matrix/retrieve/all
in an XMLHttpRequest callback.
Source
See:
See also: