views:

43

answers:

2

I've been assigned to upgrade an embedded application written in C. The application is configured via a web interface.

When the user modifies the web application a file is written to /var/www/settings.json and the file /var/www/UPDATE_SETTINGS is touched.

In the main application loop it checks to see if UPDATE_SETTINGS exists. If it does it parses the settings.json with json-c and then deletes UPDATE_SETTINGS.

This works well enough, however, we would prefer to move to an event-driven architecture (perhaps libev) in which settings.json is fed directly into the program by the webapp script to a plain-old UDP port and then issue a callback to perform the update.

What are some other elegant ways to solve this problem? Should we just stick with the current approach?

A: 

I am making some assumptions here.

1) you are connected to the internet all the time with you embedded device. 2) your device can set up interrupts on things like "USART RX buffer not empty"

note: depending on what kind of hardware you are using you could set up interrupts on things like pings and other stuff this could be another way of interrupting the embedded device.

if those two assumptions are correct you could do this, have another "script" on a server or computer somewhere that watches the /var/www/settings.json for changes you could use something like rsync to watch for changes. this "script" when it notices that the json file changes will communicate to the embedded device using tcp/ip you can either ping the device or just send the file over. If you can set an USART interrupt on the embedded device then the device will be able to detect the data coming in and therefore respond by either reading the data you are sending or going to the website to download the json file to be parsed.

this way you will have an event drive embedded device and it will not waste time checking to see if this json file has changed.

I hope this helps

jramirez
The web application is for configuration. The device isn't often connected to "the Internet". However, we do have 3rd parties who POST to the web app on the device to change the settings with their own applications.
CoolAJ86
What kind of connection does the device have ?Is there any way to cause it to connect ?
jramirez
+1  A: 

Just use inotify. It was created for cases like yours.

kazanaki
I suppose that'll work well enough. Thanks.
CoolAJ86