🤖Have you ever tried Chat.M5Stack.com before asking??😎
    M5Stack Community
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    pm2.5 and mqtt incomplete python code

    Bases
    4
    4
    8.9k
    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.
    • J
      jpilarski
      last edited by

      Before I go into describing the bug I ran into I want to make a request that the pm2.5 blocks includes temperature and humidity values from the sensor. Now onto the issue:
      I am using uiflow with pm2.5 and mqtt blocks. I start off with some block code for the pm2.5 that is working well but when I try to add the mqtt blocks the generated python code is incomplete and it doesn't include the mqtt python code even when there are mqtt blocks. Sometimes, depending on the sequence of when I add the mqtt blocks it will even remove previously generated python code that was and should still be there. If I then try and go back from the python tab to the blocks tab uiflow will lock up and I then need to reload the m5f file. I can get the code to work by typing it into the python editor but I can't get it working using blocks. Here is the file with the blocks and you can see the incomplete python code it generates. I am using 1.3.4 beta pm25 m5f on github

      Here is the working python code that I manually typed into the python editor tab.

      from m5stack import *
      from m5ui import *
      from uiflow import *
      import module
      from m5mqtt import M5mqtt
      import unit
      
      setScreenColor(0x222222)
      
      
      m5mqtt = M5mqtt('xxx, 'io.adafruit.com', 1883, 'xxx', 'xxx', 3000)
      
      pm0 = module.get(module.PM25)
      
      i = None
      ioTopics = None
      xPos = None
      yPos = None
      pmText = None
      pmVal = None
      xPos = 5
      yPos = 16
      
      def upRange(start, stop, step):
        while start <= stop:
          yield start
          start += abs(step)
      
      def downRange(start, stop, step):
        while start >= stop:
          yield start
          start -= abs(step)
      	
      m5mqtt.start()
      pmText = ['SPM 1.0', 'SPM 2.5', 'SPM 10', 'APM 1.0', 'APM 2.5', 'APM 10', '# >  0.3 um', '# >  0.5 um', '# >  1.0 um', '# >  2.5 um', '# >  5.0 um', '# > 10.0 um']
      i_end = float(len(pmText))
      for i in (1 <= i_end) and upRange(1, i_end, 1) or downRange(1, i_end, 1):
        lcd.print(pmText[int(i - 1)], xPos, (yPos * i), 0xffffff)
        wait_ms(300)
        
      #ioTopics = topic_data
      #i_end2 = float(len(ioTopics))
      #for i in (1 <= i_end2) and upRange(1, i_end2, 1) or downRange(1, i_end2, 1):
      #  lcd.print(ioTopics[int(i - 1)], 150, (yPos * i), 0xffffff)  
       
        
      while True:
        pmVal = [pm0.get_pm1_0_factory(), pm0.get_pm2_5_factory(), pm0.get_pm10_factory(), pm0.get_pm1_0_air(), 
        pm0.get_pm2_5_air(), pm0.get_pm10_air(), pm0.get_num_above_0_3(), pm0.get_num_above_0_5(), 
        pm0.get_num_above_1(), pm0.get_num_above_2_5(), pm0.get_num_above_5(), pm0.get_num_above_10()]
        i_end2 = float(len(pmText))
        for i in (1 <= i_end2) and upRange(1, i_end2, 1) or downRange(1, i_end2, 1):
          lcd.print(pmVal[int(i - 1)], (xPos + 130), (yPos * i), 0xffffff)
          m5mqtt.publish(str('xxx/feeds/pm2-5.pm-1'),str(pmVal[1]))
          m5mqtt.publish(str('xxx/feeds/pm2-5.pm-2-5'),str(pmVal[2]))
          m5mqtt.publish(str('xxx/feeds/pm2-5.pm-10'),str(pmVal[3]))
          m5mqtt.publish(str('xxx/feeds/pm2-5.pm-2-5'),str(pmVal[2]))
          #pm2-5.particles-0-3
          wait_ms(200)
      
      1 Reply Last reply Reply Quote 0
      • E
        Efried
        last edited by

        that is frequently the case that one ends by manually adapting the code.
        BTW: do you have some description of the functions, like get_pm2_5_factory which delivers values in µg/m³, the number of particles is per dm³ acc https://www.aliexpress.com/item/32725547467.html

        1 Reply Last reply Reply Quote 0
        • ajb2k3A
          ajb2k3
          last edited by

          You can't edit micropython and then switch back to blocks as your edited code wont have a matching block code in its librarys.
          Also last time I checked, temperature and humidity from the PM2.5's internal sensors are not supported.

          UIFlow, so easy an adult can learn it!
          If I don't know it, be patient!
          I've ether not learned it or am too drunk to remember it!
          Author of the WIP UIFlow Handbook!
          M5Black, Go, Stick, Core2, and so much more it cant be fit in here!

          1 Reply Last reply Reply Quote 0
          • MatiM
            Mati
            last edited by

            This is already requested some time ago via git. Still not filled.

            1 Reply Last reply Reply Quote 0
            • First post
              Last post