Home automation project with led gpio - Relay controled from web ui

Hi there!
I'm trying to do something like this

I'have 3 old TL-WR740n v4.20 and I wanted to use the led of the router as relays outputs.
First I've set it to wireles client, and went to System/Leds and renamed some unused leds to out1 to out6. Also set the led trigger to none

after that I found out that in SSH i can get some led status by
# uci get system.out1.default

and i can turn a led on or off with (1 to on, 0 to off) :grimacing:

# uci set system.out1.default=1      
# uci commit
# /etc/init.d/led restart

:smile: felling happy I started to create the web ui to control the leds

very simple:
six forms
each one get one checkbox with a onChange="this.form.submit()"
so here begins my problem: i couldn't make the script work. I've made a lot of scripts to the formAction but none worked.

then I gave up and tried crelay... unsucessfully. It is almost what I need, but is focused in Usb Relays boards.
I want to use my routers leds, some old relays and transistors that I have at home.
my device doesn't have a lot of free space, only 68kb. (it is trashy, but not useless)
Now I'm back in the beggining with almost nothing.

Could somebody help me with this? if you do only one I can do the others.

what I'm trying to do is:
get the led status, dispay the checkbox accordingly, and toggle the led. without any packages besides the ones already compiled. uHttpd, luci and etc

If this work, I'll do the eletronics after.

I am not going to answer your question, but...

The "normal" procedure for controlling LEDs is not by changing the default configuration using "uci". All controllable LEDs should be accessible at "/sys/class/leds"; you can just read and write from those "files".

If you share your code others can have a look at it, and point where could be the issue.

If you are willing to enter the rabbit hole, search for these terms, and keep yourself entertained for an evening or two: HomeAssistan, Domoticz, Tasmota, ESPHome, OpenHAB, Arduino, ESP8266, ESP32, firmata, ...

1 Like

Thanyou :smile:

In my google search i saw that everybody does this way (/sys/class/leds), but in my tests when the router reboot it always back to defaults set in the config files. I was thinking about that. if the router reboots, it returns in last state

From the list I only know 2 terms: arduino and Domoticz. I'll do my homework :smile:

I only have a static html page :frowning_face: I tried to make it dynamic.. I did like the LuCI index.html
and called a script in /www/cgi-bin ... in what language should this script be? is it lua? everything I tryed I have failed. I've even copy/paste a Hello World and it didn't run (permissions 755)
I miss something like

display_errors = on

<form action="/cgi-bin/out1>
 	<input onChange="this.form.submit()" type="checkbox" checked>

In this case I don't have the out1 file anymore but the idea was

  • Check state
  • if 0, set to 1
    else, set to 0
  • commit
  • restart service

theese all are device specic Home automation software. The ideia is to recycle this old and unsuported router, giving it some extra-life

Because of your resource constraints, best to have static HTML only.
LUA should also be possible to be used.
In case, you can drop LuCI completely, streamline your 18.06 (?) by removal of non-required stuff (PPP etc.), debug file system etc. and you are willing to build custom image, you might be able to install PHP.

1 Like

I just found this Example of web interface using uHTTPd and Lua
but it didn't worked too :weary:

actually... crelay supports raw gpio outputs... ( depending on your release... you may need to unload/uninstall a module or edit your dts to free up the gpio's )

Sorry, I have no expirience in using LUA on openwrt to serve and process web pages.
But I used PHP rather extensively on openwrt-devices having more resources.
However, the 4/32 might be sufficient enough for some old openwrt, which you need to use, anyway, and some streamlined PHP. Assuming, you give up LUCI, and some more.
Frankly speaking, interesting question, whether it will fit. Which version of openwrt do you use ?

1 Like

now: 18.06.9
but with the 17.01.5 I have more free space.

thats much easyer to me. but the device can't even do a 'opkg update' > "Only have 0kb available on filesystem"

OK, I will try to build a minimal image for your device, without LuCI, and some more streamlining. But having PHP. Lockdown is boring, anyway :slight_smile: Will let you know, whether it is possible. 17.01.5 should be best, because of PHP5 (I hope).

1 Like

that would be perfect!! anyway, I don't use PPP, neither ipv6 (my isp dont provide)

I tried to remove the packages after instalation to free some space, but without success

Package removal does not release the space in flash.
Either to use imagebuilder, or, even better, build from src. Which I will do.
Should be ready tomorrow, latest.

1 Like

I'll be waiting :star_struck:
Thank you! I'll start coding my php page :smiley:

Yes, that is expected behaviour. Bear in mind that each time you reconfigure the defaults, you are writing to your device's flash memory, which has a limited lifespan.

Wait, until confirmation, that PHP fits into flash, at least. You will still check, whether is can run in 32MB, as I have no test device.

1 Like

:hushed: I didn't knew that

but anyway. it is an old device, it is slow, 4/32, not suported anymore. its lifespan was over when I got it

I can't wait still. If this COVID situation doesn't end soon I'll get crazy
I need to keep my mind busy

Having ubuntu 18 or 20 only, I need to build openwrt 18.06, because 17.01 does not compile. Would need ubuntu 16 for compilation, obviously.

1 Like

with opkg I can only find php7 and php7-cgi is very big. I think that there is no way php7 will fit in this device