DoESLiverpool / somebody-should

A place to document practices on the wiki and collect issues/suggestions/to-do items for the physical space at DoES Liverpool
31 stars 11 forks source link

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

Closed ajlennon closed 5 years ago

ajlennon commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

Nice!

ajlennon commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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

ajlennon commented 5 years ago

Python programmers. I shall say no more

goatchurchprime commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

I wonder though which thing we need to be more aware of, when the water is refreshed or when the infusion is replaced? We could press it each day for fresh water but the fruit inside could be a week old!

On 23 Aug 2018, at 12:19, Zarino Zappia notifications@github.com wrote:

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?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/DoESLiverpool/somebody-should/issues/870#issuecomment-415380176, or mute the thread https://github.com/notifications/unsubscribe-auth/AABqa2s-3MRSZM1FWqvIv4Wa1DA7deKEks5uTo_fgaJpZM4VtCnS.

zarino commented 5 years ago

@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 commented 5 years ago

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

zarino commented 5 years ago

@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 commented 5 years ago

Are the scales that the coffee pot used to sit on still around? Aren't they already set up to report to the internet anyway, so could be altered (I imagine) relatively easy to talk to the LED screen by the water.

On Thu, Aug 23, 2018 at 12:35 PM, Zarino Zappia notifications@github.com wrote:

@ajlennon https://github.com/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?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/DoESLiverpool/somebody-should/issues/870#issuecomment-415383777, or mute the thread https://github.com/notifications/unsubscribe-auth/AIp8MC2mM6zVvcbcXGLfps4YKNKwQlJSks5uTpNvgaJpZM4VtCnS .

goatchurchprime commented 5 years ago

@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 commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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

ajlennon commented 5 years ago

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?

ajlennon commented 5 years ago

Something like this?

https://www.ebay.co.uk/itm/Self-Adhesive-Magnetic-Sheet-Approx-A4-1-5mm-Thickness-by-The-Magnet-Shop/332715589652?hash=item4d77650014:g:s5IAAOSw9CVbRgJ2

goatchurchprime commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

moved to wiki