What's new

How to get status of aimesh nodes from command line?

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

Laxarus

Regular Contributor
Hello guys,
As the title says, I need to get the status of the aimesh nodes from command line to update some sensors.
I only found
asus_device_list and cfg_device_list in the nvram but they are not enough.

Is there a way to get the this information using command line?
Node ip address
Node MAC address
Offline
Online with ethernet backhaul
Online with wireless backhaul
 
All that info is available at the mesh root in the gui. My guess is that you want to automate something. You can access the mesh nodes via ssh if the root router has it enabled (the nodes will have ssh enabled) However, only the MAC address will be in NVRAM. ifconfig will get you some info.
 
OK, so I have planned some steps

1- Access to main router and get the ip addresses of the nodes. (In this case which parameter is more reliable asus_device_list or cfg_device_list? What is the difference? Both MAC and ip addresses are listed there)
2- Ping the ip address from the step 1 and check if it is online
3- If online, ssh into node then how to get backhaul status?
 
I have struggled with this but after extensive testing. It is not a reliable method.
I can see the status of the nodes on the webui but how to get this info from the command line?
Basically,
How to get the connection status of each node? (Off, Wifi, Ethernet, IP, and MAC)
I don't exactly know the use of asus_device_list and cfg_device_list but they don't work anyway.
I tested this by unplugging the ethernet cable of node. The node went to wifi backhaul mode. I could see it on the UI but asus_device_list and cfg_device_list values didn't reflect anything.
Maybe @RMerlin has a way?
 
AiMesh is closed source. I have no control at all over its functionality.
 
AiMesh is closed source. I have no control at all over its functionality.
I was hoping some status indicator or something similar would be accessible but I guess it is not.

It is just frustrating seeing it on the webui but being unable to access it.

Hmm, another option would be using jquery or sending GET requests to web server periodically since <div id="onBoarding_block"> seem to include some useful info but that would make logging in from another client problematic

I was hoping adding the status of the nodes to the snmp using snmpd.conf.add.

Any other ideas are welcome
 
Well, I tried a couple of things but couldn't find a reliable way.
What I did is to use asuswrt integration and track the LAN MAC address of the node (I use wired backhaul), if it goes offline I get a notification.
YAML:
- id: '1616626604638'
  alias: Lyra Down
  description: Lyra not in Ethernet Backhaul
  trigger:
  - platform: state
    entity_id: device_tracker.lyra_o1_lan_asuswrt
    to: not_home
    for: 00:00:30
  - platform: state
    entity_id: device_tracker.lyra_m1_lan_asuswrt
    to: not_home
    for: 00:05:00
  - platform: state
    entity_id: device_tracker.lyra_s1_lan_asuswrt
    to: not_home
    for: 00:05:00
  condition:
  - condition: state
      # condition for router status, if router is not working properly, no point for this
    entity_id: switch.router_wol
    state: 'on'
    for: 00:05:00
  action:
  - service: notify.notify
    data_template:
      title: Wi-Fi Mesh Error
      message: "{% if trigger.entity_id == 'device_tracker.lyra_m1_lan_asuswrt'\
        \ %} \n  Problem on m1 wi-fi mesh node.\n{% elif trigger.entity_id\
        \ == 'device_tracker.lyra_o1_lan_asuswrt' %} \n  Problem on m1 wi-fi\
        \ mesh node.\n{% elif trigger.entity_id == 'device_tracker.lyra_s1_lan_asuswrt'\
        \ %}\n  Problem on s1 wi-fi mesh node.\n{% else %}\n  Unknown problem on Wi-Fi\
        \ meshg.\n{% endif %} "
  mode: queued
  max: 10

For some reason, wifi MAC address constantly changes for lyra units. I have no idea why.
 
Hey @Laxarus

today again, my network node was offline again, when it goes offline, i can still ping it, i can still access all LAN clients connected to it, only the wifi clients are dropped
the state in HA, is still "home" ... how come your state is "not_home" ? are you not able to ping it when its offline?

its frustating , i have no clue why its offline, stilll reachable on my network

i think gonna setup a reboot schedular on those nodes , once a week or something like that

1629288948894.png


1629288923878.png
 
Hey @Laxarus

today again, my network node was offline again, when it goes offline, i can still ping it, i can still access all LAN clients connected to it, only the wifi clients are dropped
the state in HA, is still "home" ... how come your state is "not_home" ? are you not able to ping it when its offline?

its frustating , i have no clue why its offline, stilll reachable on my network

i think gonna setup a reboot schedular on those nodes , once a week or something like that
I am trying to come up with some detailed sensor for the nodes. It will detect whether the node is offline, using ethernet backhaul or wifi.
I will post it here when I complete it.
Can you give me these information omitting mac addresses?

What is the result of the "nvram get cfg_device_list"
- When all your system is online
- When a node is pingable but shows offline
- When a node is totally offline
 
ok, well, i need to wait again like 2-3 weeks before my nodes goes offline again :-(

will post it here again then
i alteady did an reboot now of the node
 
i am also trying to setup the scheduled reboot with the lines :
nvram set reboot_schedule

but seems the timestamp is lost after a reboot, i think its because its not enabled on the main router, and the scheduler gets synched with the main router after a reboot
 
i am also trying to setup the scheduled reboot with the lines :
nvram set reboot_schedule

but seems the timestamp is lost after a reboot, i think its because its not enabled on the main router, and the scheduler gets synched with the main router after a reboot
You can try a ssh automation from home assistant to schedule a reboot.
 
yeah, gonna to that indeed, but i wait now untill its offline again to provide you the info
I had free time this week so I think I managed to get it right this time and created a sensor to accurately track the status of the aimesh devices. Fingers crossed. Apparently when a node is offline, it disappears from cfg_device_list. So we have to query and track the status of the device using that.
Tracking by ip is not reliable if you don't have a static one. So the guaranteed way is to track by MAC address which is totally static.

I will explain the steps to create this sensor in Home Assistant but this needs more testing in different conditions. If you use this method and notice something is wrong, please let me know.

First of all, we have to query the router to get the cfg_device_list values. There are a couple of options to do that but I found that the most reliable one is using SNMP.
You can publish this value extending your snmp agent using merlin fw.

create a file aimesh.sh with content:

Bash:
#!/bin/sh
nvram get cfg_device_list
place this file into /jffs/scripts/snmp/ folder. If it doesn't exist, just create the folder.
give executable permission to the file:
Bash:
chmod +x aimesh.sh

create or edit snmpd.conf.add file inside /jffs/configs by adding below line

Code:
extend .1.3.6.1.2.1.25.1.28 aimesh /bin/sh /jffs/scripts/snmp/aimesh.sh

Go to webui of the router and enable snmp.

Now the router should be advertising this value with the snmp agent.
The good thing about this method is you don't need to query the router. It consumes less resources and there is one less point of failure.

You have to find the OID for this value now. You can use any mib browser to do that.
The OID might be the same or different from mine.
Mine is .1.3.6.1.2.1.25.1.28.3.1.1.6.97.105.109.101.115.104

Next is to create a SNMP sensor in the home assistant.
I will just paste my configuration

YAML:
#   #AIMESH STATUS
- platform: snmp
  host: 192.168.1.1
  baseoid: .1.3.6.1.2.1.25.1.28.3.1.1.6.97.105.109.101.115.104
  name: "Aimesh Devices"
  accept_errors: true
  default_value: 0
  version: 2c
  value_template: '{{ (value.replace("<", " ").replace(">", " ").lstrip()).split(" ") }}'
  scan_interval: 35

Next create two "input_text" helpers for each of your nodes.
One is for storing MAC address the other is for storing the last known ip of your node.
input_text_node1_mac
input_text_node1_ip
input_text_node2_mac

input_text_node2_ip

Get the MAC address of your nodes from cfg_device_list and enter them into appropriate mac input texts manually.

Now create a template sensor for each of your nodes. This template sensor is the one that will give the final status of the node. It will check cfg_device_list and native device tracker of asuswrt integration to indicate the status of the node.

YAML:
- sensor:
    # Aimesh Status Sensor for Node 1
    - name: "Aimesh Node1 Status"
      unique_id: "Aimesh Node1 Status"
      icon: >-
        {% if is_state('sensor.aimesh_node1_status', 'Wireless Backhaul') %}
          mdi:wifi
        {%elif is_state('sensor.aimesh_node1_status', 'Ethernet Backhaul') %}
          mdi:ethernet
        {%else%}
          mdi:close-network-outline
        {%endif%}
      state: >-
        {% if states('input_text.node1_mac') in states('sensor.aimesh_devices') and is_state('device_tracker.node1_lan_asuswrt', 'home') %}
          Ethernet Backhaul
        {% elif states('input_text.node1_mac') in states('sensor.aimesh_devices') and is_state('device_tracker.node1_lan_asuswrt', 'not_home') %}
          Wireless Backhaul
        {%else%}
          Offline
        {%endif%}
      attributes:
        ip: >-
          {% if not is_state('sensor.aimesh_node1_status', 'Offline') %}
            {% set master_list = states('sensor.aimesh_devices').replace('[','').replace(']','').replace("\'",'').replace(' ', '').split(',') %}
            {% set master = namespace(device=[]) %}
            {% for x in master_list|batch(4)  %}
              {% set master.device = [x] + master.device %}
            {%endfor%}
            {% for x in master.device %}
              {% if states('input_text.node1_mac') in x %}
                {{master.device[loop.index0][1]}}
              {%endif%}
            {%endfor%}
          {%else%}
            {{ states('input_text.node1_ip') }}
          {%endif%}

      availability: >
        {{ not 'unavailable' in
            [ states('sensor.aimesh_devices') ] }}

    # Aimesh Status Sensor for Node 2
    - name: "Aimesh Node2 Status"
      unique_id: "Aimesh Node2 Status"
      icon: >-
        {% if is_state('sensor.aimesh_node2_status', 'Wireless Backhaul') %}
          mdi:wifi
        {%elif is_state('sensor.aimesh_node2_status', 'Ethernet Backhaul') %}
          mdi:ethernet
        {%else%}
          mdi:close-network-outline
        {%endif%}
      state: >-
        {% if states('input_text.node2_mac') in states('sensor.aimesh_devices') and is_state('device_tracker.node2_lan_asuswrt', 'home') %}
          Ethernet Backhaul
        {% elif states('input_text.node2_mac') in states('sensor.aimesh_devices') and is_state('device_tracker.node2_lan_asuswrt', 'not_home') %}
          Wireless Backhaul
        {%else%}
          Offline
        {%endif%}
      attributes:
        ip: >-
          {% if not is_state('sensor.aimesh_node2_status', 'Offline') %}
            {% set master_list = states('sensor.aimesh_devices').replace('[','').replace(']','').replace("\'",'').replace(' ', '').split(',') %}
            {% set master = namespace(device=[]) %}
            {% for x in master_list|batch(4)  %}
              {% set master.device = [x] + master.device %}
            {%endfor%}
            {% for x in master.device %}
              {% if states('input_text.node2_mac') in x %}
                {{master.device[loop.index0][1]}}
              {%endif%}
            {%endfor%}
          {%else%}
            {{ states('input_text.node2_ip') }}
          {%endif%}

      availability: >
        {{ not 'unavailable' in
            [ states('sensor.aimesh_devices') ] }}

Now we have the active status of the nodes. But I wanted store the last known ip to the ip attribute of the sensor to reboot via ssh in case it shows offline but pingable.
An automation like that will do the trick to store the last known ip to the input text ip of the node.

YAML:
alias: Store Aimesh Last Known IP Addresses
description: ''
trigger:
  - platform: state
    entity_id: sensor.aimesh_node1_status
    id: aimesh_node1_ip_change
    for: '00:00:20'
    to: Offline
  - platform: state
    entity_id: sensor.aimesh_node2_status
    id: aimesh_node2_ip_change
    for: '00:00:20'
    to: Offline
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: aimesh_node1_ip_change
        sequence:
          - service: input_text.set_value
            target:
              entity_id: input_text.node1_ip
            data_template:
              value: '{{trigger.from_state.attributes.ip}}'
      - conditions:
          - condition: trigger
            id: aimesh_node2_ip_change
        sequence:
          - service: input_text.set_value
            target:
              entity_id: input_text.node2_ip
            data_template:
              value: '{{trigger.from_state.attributes.ip}}'
    default: []
mode: parallel
max: 10


This should be it. Let me know how that works out for you.
 
looks great, but why not use a SSH sensor? and then run the command : cfg_device_list

next time it fails here, gonna try the commands to see the actually output, mine Mesh node do have a static IP
 
looks great, but why not use a SSH sensor? and then run the command : cfg_device_list

next time it fails here, gonna try the commands to see the actually output, mine Mesh node do have a static IP
I prefer to use SSH sensor as the last option. There are various reasons but in summary:
Snmp is more secure
Snmp uses less resources
You don't have to login the host device periodically, host device by itself advertises what you want.
It is easy to debug. You can just alter the script on the host device instead of completely rebooting home assistant.
Snmp is more stable and less likely to fail.
Snmp is designed to do stuff like this. SSH is more like a hacky way to achieve what you want.
 
i had a quick look at your code for uour sensors, you check the state "home" or "not_home"
when my node was offline last week, it was still in "home" state...
If your node is offline, can you still ping it at that point?

If mine node is in offlline state , i can still ping it, i can even ping other lan devices connected to it, i can still SSH access to that speficic node
its just showing in Offline state on aimesh page, and all wifi devices are disconnected
 
also trying out now the snmp sensor, i think my mib values are different
i have installed mib browser, what do i need to look for?

1629742875890.png



1629742846326.png
 

Similar threads

Latest threads

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top