[Swansea Hackspace] Controlling my kettle with Wemos D1 mini ESP8266

Justin Mitchell justin at discordia.org.uk
Tue Apr 18 12:35:32 BST 2017


On Tue, 2017-04-18 at 10:12 +0000, David Davies-Day wrote:
> Hi all, thanks to everyone that tried to help me with this last night
> and hello to anyone who has not seen this yet.
> 
> Early this morning I fitted a tiny phone charger in the lowest part
> of the kettle and ran the 5V wires up to the 5V pads of the WeMos and
> it works.......
> I have a few small problems Though, if the web page "Kettle On"
> button is pressed multiple times it keeps "pressing" the start button
> of the kettle and if you're not stood next to the kettle it is not
> possible to see if the kettle has started boiling. It stores the
> number of web button presses and continues till it has done them all.
> 
> This is the kettle...
> https://www.aldi.co.uk/ambiano-temperature-control-kettle/p/094446104
> 766000
>  
>   Ambiano Temperature Control Kettle - ALDI UK www.aldi.co.uk
> A premium 1.5 litre kettle electronic control, an illuminated water
> gauge and 7 preset temperature settings for the perfect brew.
> Can anyone help please?
> 
> I would like to find a way to only allow the pin and opto isolator
> (this is bridging the on button to simulate the button being pressed
> when the ESP pin is HIGH) to only "press" the on button once till the
> kettle has boiled or the web page cancel button (//commented out in
> code, not yet used), has been pressed.
> 
> The WeMos D1 mini I am using has one analogue in pin, it would be
> nice to be read a thermistor and display the value on the web page.
> If anyone can point me to any suitable tutorials for my issues or
> give me some snipits of code to try that would be awsome, I would
> like do this all myself but if anyone want to write a full code that
> would also be cool.
> 
> Opto isolator for the button is on pin 5 active HIGH resting LOW.
> indicator LED is on pin 2, active HIGH resting LOW.
> Might be possible to tap existing thermistor, if not I can add a
> dedicated one.
> 
> Please find attched .ino file or see code below.
> All the best, Dave.
> 


Temperature from a thermistor is a nice simple circuit, a voltage
divider, with the thermistor taking the place of one of the two
resistors, giving you a voltage that changes with temperature. 

Examples like this:
http://esp8266tutorials.blogspot.co.uk/2016/09/esp8266-ntc-temperature-
thermistor.html


As for the code in general, you need to be careful with web programming
like this that you don't attempt to perform actions that take time, or
wait for results in the middle of answering web requests.

The handling of web pages should only set and query variables that
control the state of the main loop, returning as quickly as possible,
and have the main loop handle performing the actions and waiting for
results.

Also, once you are past the initial setup, if waiting for time to pass,
or any kind of time delay, do not use delay(), you should instead be
using a timer like millis(), note down the time when you started, then
each time around loop() you check if enough time has passed yet.

For your kettle you may want similar ideas, the request that turns the
kettle on starts a timer, any subsequent requests can see a timer is
already running and just ignore the request. and the main control loop
will eventually see that enough time has passed and turn it off again.
possibly even keeping record of how long ago it last boiled, and
refusing any further requests that are too soon.

So, to reiterate, use millis() to time things, it returns a number,
1000 per second, which counts up. It will loop around to zero again
roughly once every 59 days.

I would also suggest for handling the web content you look at using the
ESP8266WebServer library.

you will spend a lot less time worrying about creating valid http
headers and other minutia, it also helps encourage the right kind of
separation between your main loop and the handling of web requests.


For an example project that uses these techniques, plus some other more
advanced stuff like wifi configuration managers and real-world time
(ntp) look at my remote power controller project.

http://no2.stoneship.org.uk/projects/git/?p=remote_power;a=summary






More information about the Hackspace mailing list