Mudi auto shutoff

Is there a way to make the Mudi shut off after a period of inactivity. Essentially, are there any clients connected to it, if not for the last x minutes, shut down?

Given the broad scope it being based on open-wrt, its probably possible, but since most open-wrt routers aren’t battery powered, probably not something anyone else has needed.

Thanks

Sorry you cannot do that from openwrt.

Update on this, I was able to write a bash script to check for clients and to check if it was plugged in or running on battery.

Then I set a cron job to run every 5 minutes, if no clients were connected and it was running on battery it sends the poweroff command.

This sort of works, unfortunately the MCU doesn’t respond to the s3 signal that poweroff sends, so while it does turn off the device it leaves the MCU in a weird state and doesn’t power back on when plugged in and requires more effort to turn on (you have to turn it off, even though its off, then back on)

I still think this is a descent feature that should be considered for battery powered devices. Or at least provide a way to send commands to the MCU from the terminal.

I will talk with developers to see if they can give you update of MCU firmware.

e750-mcu.zip (56.1 KB)
Thanks for your comments,this MCU firmware integrates this function, you can put this firmware in the router, through a U Disk or SCP, and then execute the following two commands in sequence:

ubus call service delete ‘{“name”:“e750_mcu”}’

mcu_update /xxx/e750-mcu-V1.0.6-c9915b01fde1e85fb51f5cffb3775392.bin

Restart the router, you can shut down the router by executing the following command:

echo {"poweroff": "1"} >/tmp/mcu_message &&killall -17 e750-mcu

OLED will display “Shutting Down”

2 Likes

Pls try the new mcu firmware from @lincoln

I will give that a try, and follow up.

Thanks

This works great! Thanks!

Will I need to apply the same update after future system upgrades or will it be included in future upgrades?

Also, for others, here is the batch file I wrote.
auto-off.zip (602 Bytes)

Update, I spaced escaping the " in the added command to the auto-off script, here is the update. auto-off.zip (645 Bytes)

1 Like

hi!

i’ve updated the mcu-firmware with the given file and tried the commands to shutdown the mudi correctly, but the device does not react on the "echo {“poweroff…”-command as expected - it does not shut down or shows any reaction.

are there updates or hints to properly poweroff the device through cli?

It still works for me but I am on an older version of the firmware (V3.105), I have been hesitant to update as I fear it will break above.

@cguenther are you on latest, V3.203?

Yes, i am on 3.203. just checked github on the e750-mcu firmware. But the repo is on v1.0.5, as the firmware given here was already 1.0.6.something… and there is no flag named poweroff :frowning:

I can confirm this wiered-state you mentioned - after poweroff/shutdown -h it shows „booting“ on the oled and stucks thereafter.

I want to use the mudi as a in-car hotspot. Will have it wired up to a battery-protection circuit and would like to shutdown the unit 3h after external poweroff…

Any clues howto do so - want to keep the firmware because of some wireguard-bugs in versions before…

Pls note, in order to power off the router using script, the mcu has to come with firmware version 1.0.6

To check the firmware version, use

echo  {\"version\": \"1\"}   >/dev/ttyS0 ; sleep 0.3 ; cat /dev/ttyS0

Upgrade mcu to 1.0.7, pls first download the firmware of e750-mcu-V1.0.7-56a1cad7f0eb8318ebe3c3c46a4cf3ff.bin.zip (24.9 KB) and upload it to your router, then

ubus  call  service delete '{"name":"e750_mcu"}'
mcu_update  xxxx.bin

It takes some seconds to upload and the router will power off. Power on it manually and now you are OK to program it.

echo {\"poweroff\": \"1\"} >/tmp/mcu_message && sleep 0.3 && killall -17 e750-mcu
1 Like

To do this, you can modify the auto-off.sh script, with the following logic (the following is not actually script).

#!/bin/sh

echo "this script should run after router is powered"
power_last_connected_time
power_disconnect_duration

do
    #check if router is powered by external power

    #if external powered,
    if #powered 
        power_last_connected_time=#now
        power_disconnect_duration=0
    fi


    #if not connected to external power, 
    if #not powered
        #cal how long it has been disconnected from power
        power_disconnect_duration= #cal the difference between now and power_last_connected_time
        if power_disconnect_duration lg three hours; then
                #power off router
        if
    fi


    sleep 60 #sleep 1 minutes and check again

done

1 Like

Ok, this works! I had V1.0.6 on the device and updated to V1.0.7 and now the devices shuts down correctly, even with the external power connected on.

great, BIG THANKS to gl-inet/@alzhao! THIS, and especially THIS is the reason why i got my Devices (AR750S and mentioned Mudi) from GL-INet - have a replying, real helping! company together with great support from the community.

Thank you - looking forward to your 5G-Mudi - or even Tips how to upgrade this Thing from the EP06-E to Quectel RM5xxQ-Modules with PCI-E-to-M.2-Adapter? :slight_smile:

2 Likes

Made this tiny little script:

#!/bin/sh

shutoff="120"

echo    "# Checking if device is powered on"

mcu=$(cat /tmp/mcu_data)
searchstring="\"C\":1"
power=${mcu#*$searchstring}

if [ $power != $mcu ]; then
  echo ">>> Device is plugged in, won't exit"
  echo "0" > /root/batterytime.txt
  exit 0
fi

echo ">>> Device is on battery..."

batterytime=$(cat /root/batterytime.txt)
let batterytime+=5
echo $batterytime > /root/batterytime.txt

let timeremaining=$shutoff-$batterytime
echo "Time on Battery: $batterytime min, $timeremaining min to shutdown..."


if [ $batterytime -gt $shutoff ]; then
  echo ">>> Not plugged in, since $shutoff min on battery, shutting down"
  echo {\"poweroff\": \"1\"} >/tmp/mcu_message && sleep 0.3 && killall -17 e750-mcu
fi

Script is executed via crontab every 5 min.

It should work. Next is just testing

@alzhao Thanks for the new version. Its greatly appreciated.