Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    Alex's Corner - Week 6 - Best Practices for Deployment

    Scheduled Pinned Locked Moved Events
    webinarbest practicespycom
    18 Posts 6 Posters 4.7k Views 6 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • B Offline
      bucknall
      last edited by

      Hi Everyone,

      I will be running the next webinar at 2 pm (BST) Thursday the 18th of May, discussing best practices for deploying Pycom devices. This live stream slightly breaks the usual schedule as the Pytrack livestream was delayed a week.

      The format will be as following:

      • Introduction
      • Discussion about deployment
      • Explanations/Examples

      Please do ask any questions (either here or in the livestream chat), I'll try to answer them live!

      Visit this link next week, on the 18th of May to join in!

      https://www.youtube.com/watch?v=0TQBPYYOPCA

      Cheers,

      Alex

      Developer Evangelist - Pycom

      J 1 Reply Last reply Reply Quote 0
      • J Offline
        jmarcelino @bucknall
        last edited by jmarcelino

        @bucknall
        I am between timezones at the moment but 18th of May was yesterday?
        Sorry ignore... got confused because I saw this posted an hour ago, but the stream was yesterday..

        1 Reply Last reply Reply Quote 0
        • PiAirP Offline
          PiAir
          last edited by

          It was. :)
          (or is it "It is" ?)

          1 Reply Last reply Reply Quote 0
          • PiAirP Offline
            PiAir
            last edited by

            In the livestream you mention that

            if machine.reset_cause() != machine.SOFT_RESET:
            

            checks for a crash. But after a crash wouldn't you still want to setup the wifi?

            If I look at this list, it lists

            • machine.PWRON_RESET
            • machine.HARD_RESET
            • machine.WDT_RESET
            • machine.DEEPSLEEP_RESET
            • machine.SOFT_RESET

            But without description of what could cause any of these and also without examples of what I would want to different for each of these.
            The Pycom documentation only lists:

            • machine.PWRON_RESET
            • machine.SOFT_RESET

            Again without any further information.

            Could you explain these a bit more and possible give examples of how you would want to handle them in boot.py ?

            PiAirP 1 Reply Last reply Reply Quote 0
            • PiAirP Offline
              PiAir
              last edited by PiAir

              A little later you look at

                      while not wlan.isconnected():
                          machine.idle() # save power while waiting
              

              Since the topic is deployment:
              This loop caused me problems once, because I used it on one of my LoPy devices. At home, there was no problem. But then I took the node with me and had to unplug it's power and reboot it while being no where near the range of my WiFi network...

              I now use this code in my boot.py:

              nets = wlan.scan()
              
              for net in nets:    
                  if net.ssid == config.WIFI_SSID:
                      if not wlan.isconnected():
                          wlan.connect(config.WIFI_SSID, auth=(WLAN.WPA2, config.WIFI_PASS), timeout=5000)
                      while not wlan.isconnected():
                          machine.idle() # save power while waiting
                      pycom.rgbled(0x007f00) # green
                      time.sleep(3)
                      pycom.rgbled(0)
                      break
              

              (forgot where I've seen this, can't imagine I made it up myself)
              This then checks to see if there is a WiFi network available with the same SSID as the one in the config.py file. If so, it connects and shows the green LED for 3 seconds to indicate me that it has connected.
              So, if I start the node outside of the reach of my WiFi network it no longer tries to connect.

              1 Reply Last reply Reply Quote 0
              • PiAirP Offline
                PiAir @PiAir
                last edited by

                Ah, you explain the PWRON_RESET and SOFT_RESET later. Solves one question.
                Still not sure why I wouldn't want to init the wifi in case of SOFT_RESET?

                1 Reply Last reply Reply Quote 0
                • PiAirP Offline
                  PiAir
                  last edited by

                  OK, last one for this video. You create the interrupt handler using:

                  def pin_handler(arg):
                  

                  From this page I understand that arg contains the Pin object. So I would be able to create one handler that handles interrupts from multiple pins, correct?
                  On that page, also Pin.IRQ_LOW_LEVEL and Pin.IRQ_HIGH_LEVEL are mentioned. Would I be able to for example use that so set an interrupt that triggers a funciton if the temperature provided by an DHT11 gets to a low or high level?

                  The documentation here is a bit outdated? It states that only the Alarm class and the Pin provide the .callback() method while at least the Bluetooth class also supports it.

                  Sorry about all these questions after the livestream itself!

                  L 1 Reply Last reply Reply Quote 0
                  • L Offline
                    livius @PiAir
                    last edited by livius

                    @PiAir
                    this is about voltage/state indicator
                    IRQ_LOW_LEVEL 0
                    IRQ_HIGH_LEVEL 1 - 3V3
                    IRQ_FALLING - The falling edge of the signal
                    IRQ_RISING - The rising edge of the signal

                    think about people first, then computers

                    PiAirP 1 Reply Last reply Reply Quote 1
                    • PiAirP Offline
                      PiAir @livius
                      last edited by

                      @livius Ok...but when would I prefer using IRQ_HIGH_LEVEL over IRQ_RISING in an interrupt? Is it just there for redundancy or are there specific use case that would make you use one or the other?

                      L 1 Reply Last reply Reply Quote 0
                      • L Offline
                        livius @PiAir
                        last edited by livius

                        @PiAir
                        You can add or between and fire in both cases :-)
                        e.g.

                        Pin.IRQ_FALLING | Pin.IRQ_RISING
                        

                        are there specific use case
                        This depend - e.g. how fast signal raisin/falling

                        think about people first, then computers

                        1 Reply Last reply Reply Quote 0
                        • T Offline
                          tenspot
                          last edited by

                          Hi Alex,
                          Thank you for posting these tutorial videos, I find them very useful.
                          You refer to using a configuration file for wifi password, UUID etc., I would be grateful if you would outline the structure of this file as I would like to use this technique, but am unsure how to create such a file.

                          Regards,

                          Mervyn

                          PiAirP 1 Reply Last reply Reply Quote 0
                          • PiAirP Offline
                            PiAir @tenspot
                            last edited by

                            @tenspot have a look at this config.py and this file that uses it.

                            Basically the config.py is a .py file where you declare the variables:

                            GATEWAY_ID = '11aa334455bb7788'
                            
                            SERVER = 'router.eu.thethings.network'
                            PORT = 1700
                            
                            NTP = "pool.ntp.org"
                            NTP_PERIOD_S = 3600`
                            
                            WIFI_SSID = 'my-wifi'
                            WIFI_PASS = 'my-wifi-password'
                            

                            Then, if you want to use them in another python file, you import it using:

                            import config
                            

                            After that you can address any variable that you have defined in that config.py file like (for example):

                            config.WIFI_SSID
                            

                            etc

                            RobTuDelftR T 2 Replies Last reply Reply Quote 0
                            • RobTuDelftR Offline
                              RobTuDelft @PiAir
                              last edited by

                              @tenspot It's also a convention to write the constant 'variables' in all uppercase.

                              Without data you're just another person with an opinion.
                              Hackster | About me

                              1 Reply Last reply Reply Quote 0
                              • T Offline
                                tenspot @PiAir
                                last edited by

                                @PiAir Hi, Thanks for your reply, I didn't realise it was that simple! Thanks to Rob also for your comment on capitalisation of constants. Knowledge of these things all helps to improve my code readability and style.

                                B PiAirP 2 Replies Last reply Reply Quote 0
                                • B Offline
                                  bucknall @tenspot
                                  last edited by

                                  Hi @tenspot, apologies for the delay getting back to you, I have been busy with events this week! Thanks @RobTuDelft and @PiAir for answering these questions!

                                  Developer Evangelist - Pycom

                                  T 1 Reply Last reply Reply Quote 0
                                  • T Offline
                                    tenspot @bucknall
                                    last edited by

                                    @bucknall No problem. Thanks again for the video tutorials.

                                    1 Reply Last reply Reply Quote 1
                                    • PiAirP Offline
                                      PiAir @tenspot
                                      last edited by PiAir

                                      @tenspot You're welcome. And if you like video tutorials, I can also recommend the ones by Tony DiCola from Adafruit. Although they are not LoPy/Pycom specific (he often uses the Adafruit boards) they are very informative. That is how I learned microPython:

                                      https://www.youtube.com/playlist?list=PLjF7R1fz_OOXrI15wuXeESA0aA4VzcWSi

                                      T 1 Reply Last reply Reply Quote 2
                                      • T Offline
                                        tenspot @PiAir
                                        last edited by

                                        @PiAir Thanks for the link, I will check it out.

                                        1 Reply Last reply Reply Quote 0

                                        Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                                        Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                                        With your input, this post could be even better 💗

                                        Register Login
                                        • 1 / 1
                                        • First post
                                          Last post

                                        Pycom on Twitter

                                        Pycom