OpenWRT / GoldenORB modem statistics (mqtt)

Hi!

EDIT: I have modified the code to work with OpenWRT and ModemManager. It is far better and cooler now. It uses MQTT autodiscovery for the sensors so you don’t have to make template sensors anymore. :grinning:


Here is the code for OpenWRT firmware:

Old code underneath:
https://www.ofmodemsandmen.com/
I made a script for OpenWRT to find data from card and send as MQTT message to Home Assistant.

What do you think?
ha1

Here is the code for modem_mqtt.sh #!/bin/sh# sends modem data to mqtt server# install mqtt client: opkg inst - Pastebin.com
This works currently only with GoldenOrb OpenWRT fork. I might later modify it to work with regular OpenWRT.
Some of the code is used from rooter firmware, because they don’t support SINR data.

Here are sensors:

  - platform: mqtt
    state_topic: 'modem/status'
    name: 'Modem'
    friendly_name: '{{ value_json.name }}'
    unit_of_measurement: '%'
    value_template: '{{ value_json.signal }}'
    json_attributes_topic: 'modem/status'
  - platform: mqtt
    name: "SINR"
    state_topic: "modem/status"
    unit_of_measurement: 'dB'
    value_template: "{{ value_json.sinr }}"
  - platform: mqtt
    name: "RSSI"
    state_topic: "modem/status"
    unit_of_measurement: 'dBm'
    value_template: "{{ value_json.rssi }}"
  - platform: mqtt
    name: "RSRQ"
    state_topic: "modem/status"
    unit_of_measurement: 'dB'
    value_template: "{{ value_json.rsrq }}"
  - platform: mqtt
    name: "RSRP"
    state_topic: "modem/status"
    unit_of_measurement: 'dBm'
    value_template: "{{ value_json.rsrp }}"
1 Like

I think it has potential if you actually provide your code.

I provided the code in the OP. Still needs some work, if we would like to use it in OpenWRT.

what about, is there a version for OpenWRT?

I am just starting to get used to GoldenORB. Where do I put the code for modem_mqtt.sh? I add the sensors to the config.yaml file but not sure how to tell the GoldenOrb to send the data to the mqtt server which I already have.

Thanks for your help.

First install mosquitto client:

opkg install mosquitto-client

Place modem_mqtt.sh file into: /etc/config/
Edit the file and modify your mqtt server IP

Then run command:

chmod +x /etc/config/modem_mqtt.sh

Now the file is set as an executable. You can testi it by running command in /ect/config/ folder:

./modem_mqtt.sh

Then use GUI and go to: System → Startup
In the end there is local startup

Just add:
/etc/config/modem_mqtt.sh &

before exit 0

I assume I need to have ssh turned on on the router…

what directory hould I install the mosquito client pkg in

Will this work with non Sierra wireless modems?

You don’t need to specify a folder for installing packages.
You need SCP to transfer files to router.

Yes, as it uses GoldenOrb’s collected data.

Just for clarification

log into goldeorb router via ssh via terminal (ssh username@ipaddress)
install opkg install moaquitto-client in the default directory that ssh logs into

place the modem_mqtt.sh file in the /etc/config/ directory with the correct moquuitto ip address with SCP

Questions?

Do I need to include the port number or is it the default?

type in command chmod…
then type in command ./modem_mqtt.sh

Last step add the /etc/config/modem_mqtt.sh & to the startup local section on the gui

then restart modem

Thanks and sorry for all the questions…

Hi,

I have now made new version for OpenWRT. Check it out please. :slight_smile:

1 Like

Valexi - Finally getting around to doing this. Do I install mosquitto-client-ssl or mosquitto-client-nossl. I am guessgin the mosquitto-client-ssl?

@farberm I have nossl installed, but both should work?

I tried ssl and set Device=3 based upon my WG3526 saying the modem Dev#=3. However I am not seeing any connection…

My MQTT server requires a username and password.

I do not see an area to set that for the client in modem_mqtt.sh? Do I need to add a line?

I have installed the mosquito-client, modem_mqtt.sh (for GoldenOrb-orginal post) and made the changes to file rc.local

My modem is communicating on ttyUSB2 so I changed that in the script

When I do this I see the modem_mqtt process is started but my modem will never connect to the internet.

If I try comport ttyUSB1 same thing.
I have a quectel modem… does sleep 60 need to be longer to allow the modem to connect first like sleep 600?

Hi,

Did you put “&” mark after the startup command? It allows other commands to execute at the same time.

Beford doind rc.local changes you can run script manually in ssh with command “./modem_mqtt.sh” (in the same folder, where script file is) and see that everything is working.

I’m curious if you are still monitoring this thread. I am attempting to add this to my Goldenorb router. I am getting the not found error in my system log
Sat Jan 8 14:50:27 2022 daemon.notice procd: /etc/rc.d/S95done: /etc/rc.local: line 4: /etc/config/modem_mqtt.sh: not found

I have placed the modem_mqtt.sh file in the etc/config/ folder and set the file executable with chmod +x
I added the following to the rc.local file
sleep 60
/etc/config/modem_mqtt.sh &

Did you run into this error perhaps and know of a fix?

Thank you!

Solved the problem. My script file had carriage return / linefeeds at then end of each line. removed the

CR and now the script loads

image