Go Down

Topic: Configure a Yun application via a web page (Read 549 times) previous topic - next topic

robertics

Oct 18, 2020, 10:48 pm Last Edit: Oct 19, 2020, 07:20 am by robertics
I needed a way to manage my Yun application via a web page served by the Yun itself. I thought there would be plenty of nice examples for me to follow, but couldn't find one anywhere. So with a bit of effort I've managed to bolt together a solution. It draws upon many articles that I'd never be able to find again, though the forum topic here contained a key point about editing the /etc/config/uhttpd file.

Having finally got where I wanted to be, I thought I'd share so that it might save someone a bit of work. It's a complete working example, handling a sprinkling of HTML input types, and can easily be expanded as required for a real application.

On loading, this web page loads a configuration contained in a JSON file on the SD card and displays it as editable fields in a form. After editing, the modified configuration is posted back and written to SD card again, where a Python application can read it and check its time stamp to see if its new.

Alternatively, a new configuration file can be read from the client side and uploaded to overwrite the original configuration completely.

This example comprises the following files. Apologies for the imaginative naming.

/sd/arduino/www/config.html
/sd/arduino/www/config.js
/sd/arduino/www/config.css
/sd/arduino/www/config.json
/sd/arduino/www/cgi-bin/config.py

The web page is accessed in the browser at http://192.168.XXX.XXX/sd/yun_config.html

All the code should be in the attached zip file.


Go Up