
As is known from the popular
song of Vyacheslav Innocent, it’s not beer that is ruining people - water is ruining people. Especially when water runs out at the most inopportune moment. Something needs to be done with this, especially as there is an unused esp8266 controller and a green LED in the table
Water water
I think many of Habr's readers traditionally drink bottled water that we consume in the office and at home. It’s not that the process of ordering water somehow strains me, but in a known way it’s somehow not on IT, calling somewhere, always busy, then asking for the contract number, but where to go and how much? I decided to stop all this and make this process more interesting.
We are writing a letter
The company that delivers water to me is not very friendly with high technology, there are neither applications, nor an order from the site, but the water is very good. To order delivery you need to call the operator every time. I am writing to the support service (all the same, there was a contact e-mail on the site).
')
After some time, I receive a letter with the kind consent to receive an order for water by e-mail, which is what was required.
Button, esp8266 and green LED
Well, the idea, as many have already guessed, is terribly simple. Having an esp8266 controller, we program it to send an e-mail to the address of the water delivery company, pressing and holding the button until the green LED lights up, indicating that the message was sent successfully. Holding the button lasts 3-5 seconds. During this time, the device connects to the home WI-FI and executes this simplest code.
#include <ESP8266WiFi.h> #include "Gsender.h" #pragma region Globals const char* ssid = "HomeWIFI"; // const char* password = ""; // const char* letter_message = "! , " "2 " " ==== 19 . . ====== +7909====="; uint8_t connection_state = 0; uint16_t reconnect_interval = 10000; // - 10 #pragma endregion Globals uint8_t WiFiConnect(const char* nSSID = nullptr, const char* nPassword = nullptr) { static uint16_t attempt = 0; Serial.print("Connecting to "); if(nSSID) { WiFi.begin(nSSID, nPassword); Serial.println(nSSID); } else { WiFi.begin(ssid, password); Serial.println(ssid); } uint8_t i = 0; while(WiFi.status()!= WL_CONNECTED && i++ < 50) { delay(200); Serial.print("."); } ++attempt; Serial.println(""); if(i == 51) { Serial.print("Connection: TIMEOUT on attempt: "); Serial.println(attempt); if(attempt % 2 == 0) Serial.println("Check if access point available or SSID and Password\r\n"); return false; } Serial.println("Connection: ESTABLISHED"); Serial.print("Got IP address: "); Serial.println(WiFi.localIP()); return true; } void Awaits() { uint32_t ts = millis(); while(!connection_state) { delay(50); if(millis() > (ts + reconnect_interval) && !connection_state){ connection_state = WiFiConnect(); ts = millis(); } } } void setup() { pinMode(5, OUTPUT); Serial.begin(115200); connection_state = WiFiConnect(); if(!connection_state) // if not connected to WIFI Awaits(); // constantly trying to connect Gsender *gsender = Gsender::Instance(); // Getting pointer to class instance String subject = " "; if(gsender->Subject(subject)->Send("water*****@mail.ru", letter_message)) { Serial.println("Message send."); digitalWrite(5, HIGH); // - } else { Serial.print("Error sending message: "); Serial.println(gsender->getError()); } } void loop(){}
Everything you need fits in the palm of your hand. Programming the microcontroller is well described, for example, in this
article .
The code uses the Gsender.h library, which can be downloaded
here . A feature of the library is that it sends messages from gmail, so you need to open a Google email address for the project. In the text of the library, you must specify the login and password from the newly opened mail, but in the form of base64 encrypted phrases. We use for this, for example, this
service . There must be something like that.
const char* EMAILBASE64_LOGIN = "Y29zbWkxMTExMUBnbWFpbC5jb20=";<br>const char* EMAILBASE64_PASSWORD = "TGFzZGFzZDEyMzI=";
Perhaps the GMAIL security systems will ask for permission to use such a connection. Allow
The button only provides power to the controller while the code is being processed. On any of the ports we will hang the LED to signal the successful transmission of the message.
The device connects and is powered by two batteries and the resource is enough for 1000 orders, i.e. 10 years. The device can be configured from the network if desired, and a bunch of additional lotions can be hung on it, which, in principle, is not particularly necessary.
Despite the simplicity, the idea itself seemed pretty to me and in the spirit of really real Internet things. Using this principle, you can implement simple functions, for example, calling a taxi, your favorite pizza, or putting such a “smart” button next to a sick relative. Clicked - sms flew. It is convenient and you can help the patient at the right time. For sending SMS, you can, for example, use the
IFTTT service.
Have a nice day, everyone!