Gpy for simple Alarm via LTE M or NB-IOT



  • Hey friends,

    my plan is to use a Gpy for an simple Alarm System - if Door is open,
    send me an message.. noting fancy but.. puh, I am not used to MicroPython .. or Python and i am missing (for me logical steps)

    So basically is there a way to do this:

    Sleep, wake up, every xx minutes and log "everything's okay" (battery status, door status) maybe mqtt..? and on interrupt: send: "ALARM" to different Smartphones ( maybe mqqtPushClient App..?) those devices can turn of the alarm. - say like "stop/deactivate alarm for xx minutes"

    is there some examples I could use?? anyone there who could help?

    I am from Germany, SIM from is from 1nce. (Telekom Network)
    Oneway would be to use AWS, or a other Broker would be fine too.
    I could even install Mosquito with static IP.

    the only thing I can't figure out is, how to write code in python :D
    there is an Pycom 1nce blueprint on Github is there a way to modify this to my needs?



  • @Gijs THX :)

    i also found a script of an member using lte on MQTT - the only problem I have that after some minutes I get back

    OSError: [Errno 104] ECONNRESET
    

    is this problem on my side ( LTE connection down )?

    I also try to figure out why on one loop the print("") comes random and on a other loop it stay on one spot..



  • You could use a while loop to check on the pin state as so:

    from machine import Pin
    import time
    
    #define buttons
    button1 = Pin('P9', Pin.IN)
    ...
    
    #check button press
    while True:
       if button1() == True:
          print('button 1 pressed')
       if button2() == True:
          print('button 2 pressed')
       #we need the sleep to give the microcontroller some downtime to complete background processes
       time.sleep_ms(10)


  • I wouldn’t mind spoiling a easy solution with a lot of #infotext inside. ;)
    I had contact to 1nce in Germany and they said I can start with their blueprint on GitHub.
    I would.. if I could read it.. there is like zero #infotext..
    Of course turning on and of the alarm, using keys or mqtt would be great.

    I have one big question:
    How would I tell my gpy to wait for one pin go high and than first send any mqtt?
    „Button 1 pressed“
    „Button 2 pressed“

    Battery level ok
    Battery level low

    That would be the next steps i would try to play with to get in deeper.

    Thanks for helping :)



  • You could get started with the examples from the documentation: https://docs.pycom.io/tutorials/, get connected to WLAN or LTE, try a couple of things using the socket module, or external urequest library from micropython.

    In essence, micropython is very similar to regular python, just keep in mind there's less processing power on the development modules than what you would experience on a normal computer. Your thought process seems okay, though, there are still some caveats you'll probably run into (opening the door while sleeping, turning the alarm off reliably, detecting power loss etc.). A lot of things to learn there :)

    Im not going to spoil the project by giving you a direct solution, as there really is no unique solution. Let us know if you have any 'concrete' questions about certain aspects, and there will be a lot of people on the forum happy to help you!


Log in to reply
 

Pycom on Twitter