Currently writing a telegram bot to fetch live data from a Envrio+ phat on a Raspberry Pi…
When you run the built in example it will always print the below:
The current tempurature is 21.70818430223153 *C
The current pressure is 700.2708792437015hPa
The Current Humidty is 84.54408663293306 %
On the next print of the while loop it will give you the correct data of the environment. To get around this I need to only fetch the 2nd set of data not the first.
I’ve tried indenting the variables in a while loop but that does not work through the bot and hit a brick wall.
Below is what works in the bot but fetches the same values back as posted above, every time the weather states are fetched.
def weather(bot, update):
chat_id = update.message.chat_id
temp = bme280.get_temperature()
pressure = bme280.get_pressure()
humidity = bme280.get_humidity()
current_temp = "The current tempurature is " + str(temp) + " *C " + "nThe current pressure is " + str(pressure) + "hPa" + "nThe Current Humidty is " + str(humidity) + " %"
bot.send_message(chat_id=chat_id, text=current_temp)
The while loop stills brings the same values, not the next value in the example loop.
Any help would be appreciated
2
Answers
I was able to work through this over the last few days, it took a little longer as im still learning python as I go but before is the working code:
It sounds like the first request or the first loop initialises the bot and give back default values, thereafter you get real values.
Maybe one of these two strategies might work:
Some more code might help narrow down answers.