New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make a time-since-last-fill counter for ZarinoWater #870

Closed
ajlennon opened this Issue Aug 2, 2018 · 23 comments

Comments

Projects
None yet
7 participants
@ajlennon
Contributor

ajlennon commented Aug 2, 2018

#134 just reminded me of this ponder:

The flavoured water is wonderful but we never quite know when it was filled. Sometimes we have to say to people "umm you best not refill as it's been a day or so since this was topped up..."

What about an ESP32 TTGO mounted at the "full" level with a simple OLED count-up timer we (Zarino) resets when we (Zarino) fills it with the next batch of flavoured hydration?

@MatthewCroughan

This comment has been minimized.

MatthewCroughan commented Aug 5, 2018

Sure, I'll do that. I wanted to use Lixies since I have some spare acrylic, I'll get working on it when the networking in the laser room is sorted.

@ajlennon

This comment has been minimized.

Contributor

ajlennon commented Aug 5, 2018

Nice!

@ajlennon

This comment has been minimized.

Contributor

ajlennon commented Aug 8, 2018

Had a prototype planning session with @goatchurchprime . We are thinking of decoupling the input from the output. So a TTGO or similar which sends over LoRaWAN when the button is pressed, giving a starting time. Then the output stage can be whatever we want, LEDs or LIXIES or whatever.

Plus as a start-timing device it'll work wherever there is LoRa coverage and in future we may be able to make it energy harvesting which I want to look into

@ajlennon

This comment has been minimized.

Contributor

ajlennon commented Aug 9, 2018

Prototype is now running. There's a #DoESDash and a 7 segment display behind the water cooler.

Push one of the buttons on the #DoESDash to reset the timer.

watercooler2

Currently this is implemented via a node-red flow. The flow calculates time to display in secs/hours/days depending on what is appropriate.

To change the flow go to http://10.0.29.187:1880/#flow/d0f3c9b1.8f7558

@goatchurchprime

This comment has been minimized.

Contributor

goatchurchprime commented Aug 10, 2018

I've rewritten the code slightly. Although the future will be in working out some scriptlet technology.

var now = new Date();
var start = flow.get('start');
var tseconds = (now - start)/1000;
var tminutes = tseconds/60; 
var thours = tminutes/60; 
var tdays = thours/24; 

if (thours < 2) {
    msg.payload = "fresh."+Math.trunc(tminutes).toString(); 
} else if (thours < 10) {
    msg.payload = "old."+Math.trunc(thours).toString()+"hrs"; 
} else if (thours < 0.75) {
    msg.payload = "half day"; 
} else { 
    msg.payload = Math.trunc(thours+0.5).toString() + " days";
}
return msg;
@amcewen

This comment has been minimized.

Member

amcewen commented Aug 10, 2018

It's never going to hit the (thours < 0.75) clause, is it? Presumably s/thours/tdays?

@ajlennon

This comment has been minimized.

Contributor

ajlennon commented Aug 11, 2018

Python programmers. I shall say no more

@goatchurchprime

This comment has been minimized.

Contributor

goatchurchprime commented Aug 14, 2018

This has been recoded entirely using scriptlet technology, and now doesn't use the node-red thing at all for its logic.

The code on the display is here, and generic apart from the seven segment display. It uses async-mqtt receiving to both receive mqtt and run the code which it receives.

https://github.com/goatchurchprime/jupyter_micropython_developer_notebooks/blob/master/scriptlet_technology/MQTT_scriptlets.ipynb

The button now works by pushing a blob of code via MQTT (in chunks), which gets received and executed.
https://github.com/goatchurchprime/jupyter_micropython_developer_notebooks/blob/master/scriptlet_technology/MQTT_lowpowerbutton.ipynb

The code, inspired by Arduino structure of setup and loop, but with some async sugar is as follows (this is what is sent directly from the button via MQTT):

from sevensegmentdisplay import encodeledstring, writeledstringautoscroll
secondsperunit = 3600 # should be 3600

def phrases():
    yield 1, "fresh"
    for h in range(1, 4):
        yield 1, "fresh %d hours" % h
    yield 1, "stale"
    for h in range(4, 24):
        yield 1, "stale %d hours" % h
    for d in range(1, 100):
        yield 24, "bad %d days old" % d

@asyn.cancellable
async def setup():
    for t, ph in phrases():
        print(ph)
        encodeledstring(ph)
        for i in range(int(t*10*secondsperunit)):
            writeledstringautoscroll()
            await asyn.sleep(0.1)
        
@asyn.cancellable
async def loop():
    pass
@zarino

This comment has been minimized.

Member

zarino commented Aug 23, 2018

It’s too easy to forget to press the button.

Could we have it reset when the jar is picked up? It’s pretty much only lifted when it’s going to be emptied/refilled, so maybe a lift + replace would be a more foolproof trigger that the water has been changed?

@johnmckerrell

This comment has been minimized.

Member

johnmckerrell commented Aug 23, 2018

@zarino

This comment has been minimized.

Member

zarino commented Aug 23, 2018

@johnmckerrell This radical idea of replacing the water but not the infusion is something new to me. I’ve always just replaced them both at the same time, because 1) I wasn’t sure whether fruit that’s been in there for a day already would have enough flavour left to impart a second time round, and 2) who wants to drink mangey second-hand fruit juice? ;-)

@ajlennon

This comment has been minimized.

Contributor

ajlennon commented Aug 23, 2018

Yay! Have we got any of that pressure sensitive material stuff that @jackie1050 and @amcewen used?

@zarino

This comment has been minimized.

Member

zarino commented Aug 23, 2018

@ajlennon Yes! It’s called velostat, and you don’t need much. I think there’s some in the Wearables box on the storage rack?

@DoESsean

This comment has been minimized.

Contributor

DoESsean commented Aug 23, 2018

@goatchurchprime

This comment has been minimized.

Contributor

goatchurchprime commented Sep 15, 2018

@ajlennon I've soldered the display unit together propped it up in the obsolete panel above the TV screen at the front.

(I should change the pulsating to be a function in the script, rather than as part of the scrolling feature. https://github.com/goatchurchprime/jupyter_micropython_developer_notebooks/blob/master/scriptlet_technology/sevensegmentdisplay.py#L78 Maybe the scrolling itself should be implemented in the scriptlet? dunno)

The dashbutton is in a bag by the water. It sends its update script when you plug it in, then goes to sleep. This is the device that ought to be low enough power to work by a coin cell and only use that paper on wakeup. It could be implemented on a cheaper ESP8266. There's some notes on how to do low power on this: https://openhomeautomation.net/esp8266-battery

I still think it could be done with a plank with a cutout for the flat circuit board and slightly proud switch instead of a box, as this would be more stable for putting heavy jars of water onto (nothing can break and spill it because it's solid wood).

@goatchurchprime

This comment has been minimized.

Contributor

goatchurchprime commented Sep 15, 2018

I think such a unit would be useful in its own right, as a footpad that could be put in the floor or under a carpet. Make it robust and slightly more than one coincell thick. The switch (probably contact switch rather than mechanical switch) would be behind a slightly sprung layer of wood so that the area of response would be quite large. We need to make the device go back to sleep both when the contact is left closed or open.

Such a footpad near the front entrance could trigger the roller shutters to open for the first person.

@goatchurchprime

This comment has been minimized.

Contributor

goatchurchprime commented Sep 16, 2018

I've got working esp-201 in the usb-uart bridge draw in the spares cabinet.
https://austinlightguy.wordpress.com/2015/10/18/lessons-learned-with-esp-201/

If we remove the pins it would make for a pretty flat unit, and you can add an external antenna for better reception, given as it's on the floor under things.

I can't seem to get micropython onto it, but since all it needs to do is connect, send an MQTT message and the shut down, while working off a battery, @ajlennon might already have the sketch and libraries to do just this.

We don't yet have a good idea for the contact switch, but prototypes could be made of something with a coincell and a connection that closes to turn on an LED.

@ajlennon

This comment has been minimized.

Contributor

ajlennon commented Sep 17, 2018

Sketch? I don't sketch. I may have code... :)

@ajlennon

This comment has been minimized.

Contributor

ajlennon commented Sep 17, 2018

Doing a bit of pondering. I appreciate the applicability of a movable base to other projects but I'm keen to remove mechanical movement for reliability. What about we just take it back and do it old school?

I'm thinking we route out some wood as you said, and put a reed switch in the base to wake the ESP, then stick a magnetic pad on the bottom of the water cooler?

@goatchurchprime

This comment has been minimized.

Contributor

goatchurchprime commented Sep 21, 2018

I've installed the Ardunio library (through the library manager) which is this one: https://pubsubclient.knolleary.net/

The example connects and works on one of the very old 2 board ESP8266s belonging to Adrian, but completely fails on the ESP201. But at least it's some progress. We need a more reliable esp8266 to work with that is flat and works off coincells. Also need to check about low power modes.

I have a design for the foot plate button on your desk which can be done with 3 layers of thin ply laser cut into a sandwich. I don't know about the on-off problem I thought of this: https://www.youtube.com/watch?v=n52fvF2G0ys but we have single throw switches that don't have 3 wires.

@goatchurchprime

This comment has been minimized.

Contributor

goatchurchprime commented Sep 21, 2018

Deployed. The lead is too short and the message on the LED says on or off.

The machine.deepsleep tech is pretty good. It might give is very low power if we can get a naked esp32. https://github.com/goatchurchprime/jupyter_micropython_developer_notebooks/blob/master/scriptlet_technology/MQTT_lowpowerbutton.ipynb

@goatchurchprime

This comment has been minimized.

Contributor

goatchurchprime commented Nov 17, 2018

moved to wiki

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment