More
referral
Increase your income with Hive. Invite your friends and earn real cryptocurrency!

Send stats to MQTT server

Hi all, I’m new on the forums and I did not found any topics regarding MQTT…
I am looking a way to send out the stats of my rigs to a MQTT server and to be able to log the stats to a nice panel like Grafana, and also a realtime monitoring app like Blynk.

I am looking for commands to get the basic info of the miner, I found agent-screen log that cointains all I want, is it possible to run that command without the date output?

at the moment I made a simple shell script

a=$(agent-screen log)
mosquitto_pub -h mqtt.broker.adress -m “$a” -t /myrig

And I will do crontab to run it every minute…
I feel like this could be already solved in a most elegant way, I am wrong?

2 Likes

to follow, I would love to track in my Home Assistant using MQTT

I did “solve it” , I am sending all the output to my mqtt server, from the server side I have to parse /n character to keep only the json data… this was simple running node-red on a Raspi
but I struggling to run that script at boot, I did try chrontab but it did not work, and if I place the script in rc.local the rig wont start mining
not sure what is the best way to run a script on the hiveos default user

hi could you please share your solution ? i’d like to manage through mqtt nodered and home assistgant if possible :smiley:

1 Like

for those who want to do the same : Publish hiveos logs to mqtt broker · GitHub

2 Likes

I had a output.sh with this script

a=$(agent-screen log1)
mosquitto_pub -h 10.0.0.100 -m “$a” -t /rig

where 10.0.0.100 is my raspberry pi, and I will be publishing to the /rig topic

then under NodeRed I receive the payload and I use a function node to split the message

msg.payload = msg.payload.split(’\n’);
msg.payload = msg.payload[4] + msg.payload[5] + msg.payload[6] + msg.payload[7] + msg.payload[8] + msg.payload[9] + msg.payload[10];
return msg;

and from there to another funtion message to get the specific field, for example GPU temp

msg.payload = msg.payload.params.temp[0];
return msg;

and I am seding all to a influxdb also

Does anybody know how to run bash script at startup ?
dcjona script is great thanks for sharing

1 Like

i got several error …
root@hive192_168_100_174:/opt/scripts# ./output.sh
Error: Unknown option ‘,0.42,0.35],“miner”:“gminer”,“total_khs”:160017,“miner_stats”:{“hs”:[44199723,42’.

Use 'mosquitto_pub --help' to see usage.
root@hive192_168_100_174:/opt/scripts# ./output.sh
Error: Unknown option '51,0.44,0.36],"miner":"gminer","total_khs":160016,"miner_stats":{"hs":[44199795,'.

Use 'mosquitto_pub --help' to see usage.
root@hive192_168_100_174:/opt/scripts#

Would love a little step by step on getting this working, have just started a hiveOS setup and would love to integrate it into my home assistant.
Does anyone know if we can also start/stop miners at all? I would like the ability to stop the mining when my solar/battery drops below a certain % is all.

I’m looking at this too. How do I set it up on the HiveOS side? Do you go into Hive Shell and install something there?

I would be very interested in this, if someone could walk us through on how to have this bash script that @dcjona mentioned run every time at startup, it would be great.

I would love to monitor all my miner’s stats from home assistant too.

Or suggest any other way to get the data to HA :slight_smile:


Edit:

  • So i copied the .sh contents and filled in my HA address, selected a topic, entered username and password (that i also set in my HA’s mosquitto broker).
  • Opened shellinabox (by clicking the ip address in the HiveOS UI).
  • Initial username is user and pw is 1
  • There is a command in the initial help lines that lets you change your pwd for ssh and vnc, i suggest you do so
  • Did sudo nano
  • Pasted all my code - using right click on the background - then pasting in the box that appeared
  • Saved (crtl+o) as hiveos2mqtt.sh and exited nano
  • ran sudo bash hiveos2mqtt.sh waited for stuff to download and update
  • you can exit the script with crtl+c

From the hive side it seems to work ok.
Unfortunately im getting consecutive connections and disconnections on the Broker side.

1621543112: New connection from 10.0.0.110 on port 1883.
1621543112: New client connected from 10.0.0.110 as mosqpub|29832-rig1 (p1, c1, k60, u'hive_os_1').
1621543112: Client mosqpub|29832-rig1 disconnected.

No idea how to troubleshoot this tbh…

The hive mqtt client is working as intended (i guess), connects, publishes, then disconnects.

I’m guessing the next steps if i get it to work would be to do:

  • sudo nano /hive/etc/crontab.root
  • add a new line bash -c 'sleep 10 && /home/user/hiveos2mqtt.sh'
  • which should run it at every startup.

Again i am a total noob on linux so do these at your own risk.

Now onto reading this data with HA.

This thing wouldn’t work very well… I noticed it stopped working after a while and had some miner crashes.
So I did this:

  • Removed the -f flag after the tail command in the script. This way the script reads the last X lines of logs, connects to the mqtt and publishes, then closes.
  • Created a crontab entry to run it every minute. (* * * * * /path/file.sh)

It’s been working well for the past hour.

Enter your bash script run command in the laste line before “exit 0” in this file

/hive/bin/hive

Very cool!!!

Do you have the node-red json for this flow, I would love to check it out

This topic was automatically closed 416 days after the last reply. New replies are no longer allowed.