• The TCP connection is created and closed for each single request.

    The main code is here, modules ar attached:

    TSw=require("TSwitch");
    tsw1=TSw.create(B9, {duration: 180000});
    TSns=require("TSensor");
    rdr1=TSns.create(A4, {iv: 400, iv2: 50, offset: 76, thr: 9, both: true});
    rdr1.start(tsw1.getcbsnsr());
    drk1=TSns.create(A0, {iv: 10000, thr: 72});
    drk1.start(tsw1.getcbenbl());
    

    B9 switches the MOSFET (digitalWrite),
    A4 is the the presence sensor (analogRead of a radar module, cf. https://shop.weidmann-elektronik.de/inde­x.php?page=product&info=8),
    A0 is the 'darkness sensor' with a photo resistor.
    TSensor is meant to be a universal threashold sensor, all the parameters basically control how the raw signal is prepared such that the threshold makes sense. Both sensors call into the tsw1 switch instance passing 1 or 0.
    The system is self contained. The switch tsw1 additionally reports actions via HTTP, which seems to be of no relevance, I've checked it.

    I'll look deeper into setWatch(...irq: true). It might well be overkill, but it would be fun to get it working!
    After all, in the end, it might be not too hard, and it would be a nice 'backdoor' in case it's really needed (e.g. if I wanted to check the presence sensor every 50 ms).
    @allObjects: Fully agree. Not breaking the really great Espruino concept while beeing able to unleash the close to infinite speed of the great processor - that's the goal. It feels wrong to know that my little light switch would run perfectly if implemented in C. And my VIP customer - my wife - needs to be content ;)


    2 Attachments

About

Avatar for Steffen @Steffen started