StonkMaster is an all-in-one solution that tells you when to buy or sell your favourite stonk.
Every 15 minutes (or your chosen interval supported by Alpha Vantage),
the provided stonks.py script will update an MQTT topic telling a Sonoff to turn on/off based
on whether the stonk has gone up or down in value!
Sonoff devices typically ship with crappy Chinese firmware. Tasmota is an open-source firmware supporting
many ESP8266-based devices with lots of features.
Head to releases page and download the latest version (the
sonoff.bin variant)
Open up the Sonoff (should be as simple as removing the three Phillips-head screws on the back and gently prying)
Make sure the device isn't plugged into mains power while open!
Solder a 4-pin header to the 4 unpopulated pins on the PCB Note: Unfortunately with some newer devices it seems like
the PCB is stuck down by the PCB screw posts themselves, making removing the PCB difficult without causing damage - in
this case try to solder the header at an angle from above)
Attach the device to a computer with a serial adapter, leaving GND disconnected for now (see photos above for pinout,
don't forget to crossover the TX and RX connections!)
Hold down the button on the PCB and connect GND - this will start the Sonoff in flashing mode
Run the following command to erase the stock firmware, replacing /dev/ttySOMETHING with the path to your serial
port:
esptool.py --port /dev/ttySOMETHING erase_flash
Disconnect GND and then reconnect it while holding the flash button
Run the following command to flash Tasmota, replacing /path/to/sonoff.bin with the location of sonoff.bin that
you downloaded:
MQTT is a "machine-to-machine (M2M)/"Internet of Things" connectivity protocol", and Tasmota allows
commands to be issued to the device via messages published in MQTT topics.
You can set up your own MQTT broker easily enough, but for simplicity's sake we'll use
CloudMQTT. Sign up for a free plan ("Cute Cat") and create a new instance for StonkMaster.
Once you're done, you should see something like the following in the control panel:
Take note of "Server", "User", "Password" and "Port" - you'll need these values later.
Now that Tasmota has been flashed, you can configure it.
Plug the Sonoff into the wall and head to the WiFi settings menu on your phone
Connect to the network named sonoff-1234 (where 1234 will be a random number)
Your phone should prompt you to "sign in" to the network and bring up the configuration interface - if not, open
your phone's browser and go to http://192.168.4.1
Enter the details of your home WiFi network for the Sonoff to connect to
Hit "Save" and the device will reboot in order to connect to your network
Head to your computer and find your Sonoff's assigned IP address / hostname - this will depend on your router, but
usually involves going to the admin interface and looking at a list of connected devices (alternatively you could use
nmap!)
Type the address of your Sonoff into your browser
Go to "Configuration -> Configure Module" and set "Module type" to "Sonoff S2X" (click "Save" and the Sonoff will
reboot)
Once the device has rebooted, go to "Configuration -> Configure MQTT"
Set "Host", "Port", "User" and "Password" to the values from CloudMQTT from earlier
With the Sonoff connected to the broker, you can set up the server which actually controls the power!
Clone this repo on a machine with Docker and Docker Compose
Edit docker-compose.yaml and fill in your details (including your CloudMQTT values and Sonoff MQTT topic) - don't
forget to remove the build: . line unless you want to build the image yourself (it's on Docker Hub)
Do docker-compuse up to start the server
At this point, the stonks.py script will periodically query your stonk and tell your socket to switch on or off based
on whether it went up or down!