๐ŸŽ„โ›„โ„๏ธ๐ŸŽ It's beginning to look a lot like ADABOX-mas! The next ADABOX from Adafruit ships soon! Get yours now, or give as a gift! ๐ŸŽ„โ›„โ„๏ธ๐ŸŽ
0

IO Environmental Monitor Project
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

IO Environmental Monitor Project

by wsquared58 on Thu Jun 13, 2019 12:31 pm

I have started building this project using a Pi 3 B+. I have it working with just the BME280 sensor and I think I have that understood pretty well for when the other two sensors arrive.
I have two questions that I am not sure how to resolve.

1) Project runs fine but it is over in the examples folder as is described on the project pages. How do I move it out of that folder and have it run automatically when I power up the finished unit? Ultimately this is going to go outside in a weatherproff box and I want it to restart after a power blip or outage. Battery back up is for a later stage.

2) although I have gone round and round with the data feed for the 3 sensors on the BME280 and set different values in the setting where it asks how many decimal places, when I create the text block to display next to the line graphs that I opted for, all of the text blocks are spitting out these super long strings of numbers to the right of the decimal point.
I noticed in the code that there was a bit more code for the humidity and barometric pressure that were 'int(something something))' that I took to be code to force a whole number. INT being integer. So I got rid of that and that is what caused the long string of numbers. I understand that, but the decimal setting in the IO feed setup seems to have no bearing on what is being displayed and I haven't a clue as to how to programmatically set the number of decimal places to right of the decimal point. All I want is 2 points on right side.

Any guidance would be appreciated and if there are things in the LEARN section of IO that tell how these are accomplished feel free to point me to them.

wsquared58
 
Posts: 151
Joined: Sun Jun 09, 2019 9:13 pm

Re: IO Environmental Monitor Project

by adafruit_support_carter on Thu Jun 13, 2019 12:58 pm

1) https://learn.adafruit.com/running-prog ... r/overview

2) Can you clarify where the setting is you are referring to. Part of the IO Feed? The text block on the IO dashboard? Something you are doing in the Python code?

adafruit_support_carter
 
Posts: 13589
Joined: Tue Nov 29, 2016 2:45 pm

Re: IO Environmental Monitor Project

by wsquared58 on Thu Jun 13, 2019 1:36 pm

It's in IO when I create a line graph. I've attached a part of screen grab to illustrate. I don't really think that is source of problem since the text block doesn't have that option and I assume each block pulls the data directly.

Ive also attached a code snippet as a jpg iluustrating where I made an edit. When the code is running in the terminal window all those decimal points are not there. just one to the right of decimal point even with the code edited. It just manifests itself in the text block created in IO
Attachments
Code snippet.JPG
Code snippet.JPG (34.53 KiB) Viewed 170 times

wsquared58
 
Posts: 151
Joined: Sun Jun 09, 2019 9:13 pm

Re: IO Environmental Monitor Project

by wsquared58 on Thu Jun 13, 2019 1:37 pm

See jpg
Attachments
decimal places.JPG
decimal places.JPG (26.92 KiB) Viewed 170 times

wsquared58
 
Posts: 151
Joined: Sun Jun 09, 2019 9:13 pm

Re: IO Environmental Monitor Project

by adafruit_support_carter on Thu Jun 13, 2019 2:22 pm

Correct. The text block is separate from the line graph. You'll need to format the data before publishing it, which is essentially what you are doing with the int conversion.

adafruit_support_carter
 
Posts: 13589
Joined: Tue Nov 29, 2016 2:45 pm

Re: IO Environmental Monitor Project

by wsquared58 on Thu Jun 13, 2019 2:28 pm

I understand that roughly but the INT code forces what is reported to IO as a whole number. In the terminal window where I can see it running on the Pi it is reporting XX.X
That's what I want to send to IO. Those text blocks, if you can see my dashboard I stretched out and I think if I made it as wide as my monitor screen it would fill it with numbers.

wsquared58
 
Posts: 151
Joined: Sun Jun 09, 2019 9:13 pm

Re: IO Environmental Monitor Project

by wsquared58 on Thu Jun 13, 2019 2:50 pm

This is code for temperature: This is from the LEARN page on IO, not my code edits

print('Temperature: %0.1f C' % temp_data)--------->I changed the C to an F so it reports temp as XX.X F in the terminal window. T hat was a little confusing initially.
aio.send(temperature_feed.key, temp_data)

This is humidity code:

print("Humidity: %0.1f %%" % humid_data)
aio.send(humidity_feed.key, int(humid_data))

I changed the aio.send to:

aio.send(humidity_feed.key, humid_data)

There is a difference between the temperature print code text and the humidity print code text

temperature %0.1f C' %
humidity %0.1f %%" %

I don't understand the significance of the single quote behind C'
two %% and the double quote"

This is code from example that I have not edited. All I did was remove the INT part.

wsquared58
 
Posts: 151
Joined: Sun Jun 09, 2019 9:13 pm

Re: IO Environmental Monitor Project

by adafruit_support_carter on Thu Jun 13, 2019 3:13 pm

These are examples of Python string formatting. Python allows you to use either single or double quotes in places where string are being used. For example, either of these would work:
Code: Select all | TOGGLE FULL SIZE
print("hello")
print('hello')


The % symbol, along with the associated flags, is used to format the output of a variable in a string. Basic usage example:
Code: Select all | TOGGLE FULL SIZE
print("x = %f" % 42.123456789)

but you can add flags to modify the format:
Code: Select all | TOGGLE FULL SIZE
print("x = %05.2f" % 42.123456789)

etc.

Since the % symbol has special meaning, to actually print a % symbol you have to use the double %% format.

adafruit_support_carter
 
Posts: 13589
Joined: Tue Nov 29, 2016 2:45 pm

Re: IO Environmental Monitor Project

by wsquared58 on Thu Jun 13, 2019 3:34 pm

Okay, I understand that but it still gets back to my initial question. I understand double quotes so why is the bme280 temperature sending out XX.X. There is no INT formatting of the temperature output.
and humidity & atmospheric pressure are sending out XX,XXXXXXXXXXXXXXX if the format is the same. Is it just inherent in the sensors? Humidity isn't so big a deal to put back to the INT format but I want to convert the pressure to inches HG where there is a significant difference between 29" and 30"

It's probably obvious but I haven't ever looked at python code prior to about two weeks ago and before that my programming consisted of not much more than Hello World in Visual Basic probably 15 years ago.

wsquared58
 
Posts: 151
Joined: Sun Jun 09, 2019 9:13 pm

Re: IO Environmental Monitor Project

by wsquared58 on Fri Jun 14, 2019 12:00 pm

I did some google searching on python math operators and found some stuff about round() and decimal() that I think will do the trick. Anyone no of any places where these are used in the various projects?

wsquared58
 
Posts: 151
Joined: Sun Jun 09, 2019 9:13 pm

Re: IO Environmental Monitor Project

by adafruit_support_carter on Fri Jun 14, 2019 12:18 pm

I'd try playing around with the string formatting approach. The other confusing thing in Python is that there are two ways of doing this. The % style above is considered the "older" style. It still works, but the "newer" style is based on curly brackets and .format:
Code: Select all | TOGGLE FULL SIZE
print("x = {}".format(42.123456789))
print("x = {:05.2f}".format(42.123456789))

https://docs.python.org/3.1/library/str ... ing-syntax

The reason you are getting different results from the different values, like X.XX and X.XXXXX may be due to the default behavior when a format is not specified. When the values are printed like this:
Code: Select all | TOGGLE FULL SIZE
    print('eCO2:', eCO2_data)

what actually shows up can depend on the actual value of eCO2_data. So by using string formatting you are enforcing a specific format for all prints. And that's generally how you can get consistency in the output.

adafruit_support_carter
 
Posts: 13589
Joined: Tue Nov 29, 2016 2:45 pm

Re: IO Environmental Monitor Project

by wsquared58 on Fri Jun 14, 2019 2:13 pm

Okay thanks. I'll give that a shot here shortly. Some of this is also for my understanding. If know of a good book that might have some value feel free to let me know. I must have bought a dozen books on Visual Basic, all of them about 2 inches thick and all basically worthless for these types of electronics applications and I don't want to toss away that money the same way on Python books that are for different programming problems.

There's two things going on the way I understand it.

First is the print command which I see in the terminal window result each time it cylces and the formatting is what I want.
Second is the io.send command that shoots the values to IO. That is where things are going astray so that is what I need to format if I'm understanding your explanation correctly.

wsquared58
 
Posts: 151
Joined: Sun Jun 09, 2019 9:13 pm

Re: IO Environmental Monitor Project

by wsquared58 on Mon Jul 01, 2019 2:00 pm

Ended up with this which seems to work just fine

Code: Select all | TOGGLE FULL SIZE
aio.send(pressure_feed.key, "{:.2f}".format(pressure_data))

wsquared58
 
Posts: 151
Joined: Sun Jun 09, 2019 9:13 pm

Please be positive and constructive with your questions and comments.