- DIY
- A
Sonoff — Control devices with cryptocurrency
This project — A simple way to use cryptocurrencies to control devices.
Important: This project is intended solely for educational purposes and the study of modern technologies such as blockchain and cryptocurrencies. We do not support the use of cryptocurrencies in violation of the law. This project is created to demonstrate the operation of IoT devices and interaction with popular cryptocurrencies.
How it all started?
I live outside of Russia, where the laws regarding the use of cryptocurrencies are more flexible. A few months ago, we installed Sonoff in our IT office for employees and connected it to the coffee machine. Now it turns on only after the user transfers the required amount in cryptocurrency to the specified wallet.
Thus, we came up with a way to "collect money for coffee". When it runs out, we use the collected funds to buy a new pack. This is not only convenient but also helps automate the payment process.
How it works:
1. Device connection:
The Sonoff device is used as a base. It allows you to control the power supply to the coffee machine. First, we flashed Sonoff and integrated it with our code for working with cryptocurrencies. I will tell you how to do this later.
2. Payment process:
We printed and placed a QR code near the coffee machine, which contains the wallet data and the amount corresponding to the cost of a cup of coffee in EUR.
• The user scans the QR code using any cryptocurrency wallet.
• Specifies the amount in EUR.
• Sonoff checks if the payment has been received and activates the coffee machine for 1 minute.
3. Balance check:
Every 5 seconds, Sonoff sends a request to check the balance of the specified wallet:
• If the balance increases by the amount specified in the settings, Sonoff recognizes this as a successful payment.
• After that, the relay is triggered, supplies power to the coffee machine, and it starts working.
4. Updating the cryptocurrency value:
Every hour Sonoff sends a request through the API CoinMarketCap to update the current cryptocurrency exchange rate relative to fiat currency, such as EUR.
• This allows you to automatically recalculate the cost of a cup of coffee in cryptocurrency, even if its exchange rate has changed.
Flashing
Flashing is done through the browser. Connect Sonoff to the programmer and connect it to the computer via USB. If you have problems with this, write to Telegram, we will help.
We have several projects. The first is Sonoff for Toncoin, which uses toncenter.com to check the balance. The advantage of this solution is that registration and obtaining an API are not required, but it only works with TonCoin.
The second project, which we will describe in more detail here, is Sonoff for Toncoin, Solana, Cosmos, Algorand. It uses tatum.io to check the balance. In this case, registration and obtaining an API key will be required, but you can easily fit into the free tariff plan.
Turning on the device
• When you turn it on for the first time, if the device does not find the router, or if you press the button on the Sonoff itself, it will create an access point named "Crypto payments".
• Connect to this point (no password required) and open the browser, where enter http://192.168.4.1. Usually, after connecting to Wi-Fi, the Activ portal will automatically open, redirecting you to the desired page.
• Click "Configure WiFi" to configure.
Device setup
• Router and password: Enter the data to connect to your Wi-Fi.
• Crypto Name: Cryptocurrency of the device, for example, "Solana", "Cosmos", "Algorand" or "Toncoin". You can optionally add GPIO pins to this field. Example: Solana:12,11,22
, where Solana is the cryptocurrency of the device, and 12,11,22
are the corresponding pin numbers for the relay, reset button, and LED (RELAY_PIN,BUTTON_PIN,LED_PIN
).
• Your Wallet: Enter your wallet address to receive payments.
• CoinMarketCap API: Used to get the current Solana rate in fiat currency (get API).
• Tatum API: Used to get information about your wallet balance (get API).
• Сurrency: Select the currency in which you want to receive payment (EUR, USD, RUB, BYN, BGN, GBP, etc.). This is necessary for automatic conversion of the amount to Solana based on the current rate, which is updated every hour through coinmarketcap.com.
• Service Currency Price: Specify the price in the selected currency that the client must pay.
• Payment Tolerance: This cell indicates the allowable price error. Since the value of cryptocurrency is constantly fluctuating, you need to specify the range of deviations (in one digit) that you are willing to accept when paying.
• Relay Work Time: Specify how many seconds the relay should turn on. This can be from one second to several minutes or hours.
Which Sonoff devices are supported?
We have added support for SONOFF devices based on ESP32 (Dual R3, Mini R4, Basic R4, POW, THR316), but most of them have not been fully tested. If you encounter any problems, please contact us and we will try to help. On devices with ESP8266 (Mini R1, Mini R2, S26, S26R2) all GPIO (pins) remained unchanged. You don't need to configure anything. However, on ESP32 many pins have changed depending on the device model. We decided not to release separate firmware for each model, as this would complicate their support. Therefore, you will need to manually configure the GPIO for your device. To do this, after Crypto Name after the name of the cryptocurrency, add : then first the GPIO relay, then for the GPIO reset button, and finally the GPIO for the LED. Below you will find a list of devices and their corresponding GPIO. Just copy the required settings, and the device should work.
Dual R3 Solana:27,0,13
Cosmos:27,0,13
Algorand:27,0,13
Toncoin:27,0,13
Mini R4 Solana:26,0,19
Cosmos:26,0,19
Algorand:26,0,19
Toncoin:26,0,19
Mini R4M Solana:4,9,19
Cosmos:4,9,19
Algorand:4,9,19
Toncoin:4,9,19
Basic R4 Solana:4,9,6
Cosmos:4,9,6
Algorand:4,9,6
Toncoin:4,9,6
POW 16a Solana:13,0,18
Cosmos:13,0,18
Algorand:13,0,18
Toncoin:13,0,18
POW 20a Solana:4,0,18
Cosmos:4,0,18
Algorand:4,0,18
Toncoin:4,0,18
POW Ring Solana:21,0,13
Cosmos:21,0,13
Algorand:21,0,13
Toncoin:21,0,13
THR316 Solana:21,0,15
Cosmos:21,0,15
Algorand:21,0,15
Toncoin:21,0,15
Conclusion
We will continue to develop the project, add support for new devices and improve the current functionality. If you have any questions, suggestions or problems - feel free to write to us in Telegram. Your feedback will help us make the project even better.
Thank you for your attention, and good luck with your experiments!
Project links (GitHub)
👉 Sonoff for Toncoin (toncenter.com)
👉 Sonoff for Toncoin, Solana, Cosmos, Algorand (tatum.io)
👉 We also have a project with a screen
👉 And one more project with a screen
--
Write comment