1. If you're receiving a message that you are banned from the Current Events or Politics forums, it's not you specifically: those forums have been hidden for all users. For more info, see here.
    Dismiss Notice

Create Webhook from API information

Discussion in 'Programming & Software Development' started by Jag_Guy, Jul 26, 2021.

  1. Jag_Guy

    Jag_Guy Member

    Joined:
    Apr 19, 2006
    Messages:
    435
    Hi All,

    I have some mining servers running and wanted to automate a hard restart if they go offline. Currently I have some rigs running SimpleminingOS and each on has a TPlink Smart Plug. They are controlled via the below method which is a little convoluted, but it works. The Simplemining software itself will do a software restart, but if it loses comms or locks up then it will just hang and hence a hardware reset is required. I also have some watchdogs coming shortly which should take care of things, but I would really like a second layer of functionality to reset the rigs.

    I'm happy to pay someone to put it together and show me how to customise it for specific PC's.

    I've recently started using Zapier and IFTTT to automate and auto restart based on receiving emails from my pool saying that a rig is offline. It works great, but it takes about 30mins to get a notification from the mining pool, and with multiple apps monitoring and controlling things I'm worried that things would start working at some point, or support for something will simply disappear. On top of that paying for multiple platforms is getting pricey. I have zero experience with java or coding of any nature...may experience goes about as far as running DOS and terminal commands in Unbutu, but if I can run some sort of script from my main PC or a separate Audrino controller that is what I am trying to do.

    Right now my automation works like this:

    1. Zapier monitors my Gmail for certain tags. If an email is received with tag 'xxx' then it generates a webhook with a event.
    2. IFTTT monitors the webhooks, and when a specific tag is received, it will then turn a specific smart plug off, then on again.

    What I would like to do is:

    1. Monitor a specific rig using the mining software's API. I am assuming something like this? https://github.com/ferjul17/smos_api
    2. If a certain Rig e.g. Rig2 goes offline, or it's Hash rate drops below a specified value, then:
    3. Cycle power On and Off, with a delay of at least 2 seconds between turning the rig on and off, for the corresponding device using the TP-LINK smart plug API, which currently looks a little like this in IFTT. (I removed my device ID for obvious reasons).
    I have a separate PC that I can run it from 24/7. I'd prefer to run it within Windows, but can run it on Unbutu 20.4 if needed. I'd also be open to setting up a little Audrino PC and using the triggers on that to restart each Rig (I don't need a hard ON/OFF, just a reset is fine), in which case, point 3 above would be Audrino just triggering Switch #1, #2 or whatever to reset the corresponding PC.

    Is it too much to automate something like this, and I'm better off just using Zapier, IFTT and what not?
     
  2. Primüs

    Primüs Member

    Joined:
    Apr 1, 2003
    Messages:
    3,452
    Location:
    CFS
    If your mining pool supports reading that status - then yes this is all completely possible. For someone with little to no programming knowledge? Unlikely. It may require a lot of reading and learning, or paying someone for a custom job.

    If their API has some kind of push system, then you can get those notifications from a listening program but ultimately you'll need to decide your poll time (x) then run a script on a scheduled task every x minutes that pulls data from mining software API, then actions restarts based on the data it receives.
    I have something similar with my solar setup and nicehash API to only run my mining a) when solar is good or b) in off-peak time.
     
    Jag_Guy likes this.
  3. di_entropy

    di_entropy Member

    Joined:
    Jun 27, 2001
    Messages:
    1,360
    Location:
    Melbourne
    You could do all of this using Node-RED relatively easily.

    It is a graphical flow based programming software based on JavaScript that can pretty much talk to anything.

    Looks like some off the shelf nodes already exist to talk to the TP-Link smart plugs, and you can use a custom function node to interact with the mining software API.
     
    Jag_Guy likes this.
  4. ^catalyst

    ^catalyst Member

    Joined:
    Jun 27, 2001
    Messages:
    11,978
    Location:
    melbourne
    What do you mean by offline? As in the machine is cooked or the software on it has dropped its bundle?

    If you only wanted to know if the machine had crashed, you could probably just ping it? If no ping for N retries, do a request to the plug?
     
  5. OP
    OP
    Jag_Guy

    Jag_Guy Member

    Joined:
    Apr 19, 2006
    Messages:
    435
    Yep offline would just be a software crash, so a ping > machine and if no response > power cycle the plug, that would work fine.
     
  6. OP
    OP
    Jag_Guy

    Jag_Guy Member

    Joined:
    Apr 19, 2006
    Messages:
    435
    Sorry I didn't get a notification for this post and just saw it. I did do some digging around and Node-RED did seem to be a good way to go, and there was some functionality with the TP-Link plugs already as some posts I read on reddit had examples of people doing it. I just don't know how to setup the software to read the API's for the mining and TP-Link software, and the conditions around controlling it e.g. if offline = switch plug on and off. I might try and have a plug around over the next few days, but if someone can easily whip it up I'm happy to pay!
     
  7. darkanjel

    darkanjel Member

    Joined:
    Feb 28, 2005
    Messages:
    517
    Location:
    Sydney
    There's an alternate turn-key $70 option for hard resets, a Tasmota-plus enabled AU powerboard like this one. See the Ping Watchdog image for how it might work for you.
     
  8. OP
    OP
    Jag_Guy

    Jag_Guy Member

    Joined:
    Apr 19, 2006
    Messages:
    435
    Cheers, that one could work well and looks to have the smarts and flexibility. Pretty well priced too. I’d have to buy quite a few to have a single plug per rig….so having a separate script written by someone to operate NODE-red or even a little raspberry Pi might be cheaper.
     
  9. darkanjel

    darkanjel Member

    Joined:
    Feb 28, 2005
    Messages:
    517
    Location:
    Sydney
    OK, having now re-read your problem in depth, let's KISS...
    1. All you need is a smart ping test and then to issue a reset to the Smart Plug.
    2. You'd prefer Windows but can deal with Ubuntu.
    3. It currently takes up to 30m to receive an alert.
    Sending email alerts to your gmail is not great, there's many things that can interfere like internet outage, gmail rate limits, no service guarantee etc. Mail can be held up in spam gateways or throttled, you want to avoid using email for this case.

    Given your crash scenario, the API probably won't give you much more over a simple ping test.

    Assuming that TP-Link Smarthome API works for your TP-Link Smart Plugs, and the rigs are in the same physical location, then:
    Node-RED on Windows
    Node-RED to manage TP-Link
    Some form of ping monitoring, e.g Powershell script to monitor ping like this or this, plenty around.
    Some sort of auto-start/run on the script.

    One major problem here is it is a single source of failure, you might want to monitor the script/box or put that box on a daily hard reset.

    Alternatively, to address point 3 only, setup your own mail server for this Frankenstein purpose :D

    Finally, if the rigs are in separate physical locations then another solution would work better.

    You're probably capable of doing it all yourself :thumbup:
     
  10. di_entropy

    di_entropy Member

    Joined:
    Jun 27, 2001
    Messages:
    1,360
    Location:
    Melbourne
    I just did a bit more digging and it appears that API at https://github.com/ferjul17/smos_api has been archived. Apparently back in 2018 they added an additional Captcha to the login process which broke the API.

    I've had a quick look and it seems there is no official API documentation from SimpleMining OS, so seems like darkanjel's suggestion is going to be the best way forward.
     
  11. OP
    OP
    Jag_Guy

    Jag_Guy Member

    Joined:
    Apr 19, 2006
    Messages:
    435
    THankyou for taking the time to lay out the steps to make this happen. I'll try and find some time to sit down and start putting it together. I agree with monitoring the single source for running everything, setting it to reset once a day is no problem. Maybe if I get it to work well I'll just end up putting it on a small Raspberry Pi or something. For now I'll just try it out on my gaming PC.

    Damn, I was worried about that as it was a bit old. In saying that, there are mentions of an 'API' on the current SimpleMining OS FAQ, I'm on their discord so might hit them up about it.
     
  12. darkanjel

    darkanjel Member

    Joined:
    Feb 28, 2005
    Messages:
    517
    Location:
    Sydney
    You're welcome :)

    The fear of death is worse than death itself... You'd spend longer trying to figure out how to connect to the API than to install and test Node-RED manually controlling one of your devices (maybe 15 minutes). Note that the API won't push notify you that it's crashed... because it's crashed. If you need help with a ping script, just ask and I'm sure someone will help.
     
  13. OP
    OP
    Jag_Guy

    Jag_Guy Member

    Joined:
    Apr 19, 2006
    Messages:
    435
    Yeah I wish I'd spent the time to learn javascript and some basic programming skills when I was younger, I have a big passion for automation these days with my garden, water tanks, and now all of this. I'm sure if I learnt all of that when I was younger I'd be having a much easier time, but it is fun being on the journey. Learning Unbutu has been good fun....and sometimes not fun :D
     

Share This Page

Advertisement: