1

i am programming in python on a Raspberry Pi 3 and i have the following problem:

Raspberry has a temperature sensor and its data is printed on terminal by a simple module

    #!/usr/bin/python
    import sys
    import Adafruit_DHT
    flag = True

    while flag:

        humidity, temperature = Adafruit_DHT.read_retry(11, 4)

        print 'Temp: {0:0.1f} C  Humidity: {1:0.1f} %'.format(temperature, humidity)

i need to stop the cycle from another module, setting the flag to a False value. How can i do this? I need to have this possibility even from a button on an android application...a nonblocking queue would be the best fit, but i haven't found nothing similar on Pika documentation.

Anyone could give me some help? Thanks in advance.

Frank
  • 69
  • 6
  • 1
    Use flag as global variable, so you can set it false in another part of the code: https://stackoverflow.com/questions/1977362/how-to-create-module-wide-variables-in-python – G.Vitelli Apr 26 '18 at 11:16

1 Answers1

0

as it seems you will read this value on request from other devices. i would suggest to use a webserver. I've used Tornado for a similar project.

So, develop 2 endpoints: localhost:8000/startreading, and localhost:8000/stopreading which basically toggle the flag

volkovmqx
  • 200
  • 5
  • 17