STJRush / rpi

Lessons on getting your Raspberry Pi to do cool stuff
9 stars 3 forks source link

WaterTankSensor Questions #11

Open dobrienSTJ opened 6 years ago

dobrienSTJ commented 6 years ago

-You can probably use a piece of White Styrofoam to make sure proper reflection occurs -What data does the Thingspeak upload? Is it the CSV file? If so, how does it receive the file in the code to upload to the web and how does the code create a CSV file: #writes this data to a table (a .csv file), this is needed for the graph with open("cpu_dists.csv", "a") as log: # "a" means append to the end log.write("{0},{1}\n".format(strftime("%Y-%m-%d %H:%M:%S"),str(mode))) and the function:

`def updateThingSpeak(): #sends data to a webpage
   print('starting...') 
   baseURL = 'https://api.thingspeak.com/update?api_key=%s' % myAPI  

   try:
       print("The mode being sent to the web is " + str(mode) + "cm") 
       f = urlopen(baseURL + "&field1=%s" % (str(mode))) 
       print (f.read()) 
       f.close() 
       sleep(30) #uploads sensor values every 30 secs`

-Is this code for getting the mathematical mode of all the readings? Is this the figure going to be shown in the CSV file? print(readings_list) #prints the list and gets the mode (most common value) mode = max(set(readings_list), key=readings_list.count) print("The mode of " + str(number_of_readings) + " values is " + str(mode))

-Finally, should the limit be the number the user inputted in the first place? It is set as <10 currently: limit=input("Set a limit in cm to trigger an email alert eg. 5 ") and if mode <10 and mailAlert == 1: #sends email if mode is <10cm send_mail_alert()

There is loads of cool things in the code that will help us out but using the CSV table and an iOT system, makes it a very powerful system altogether!

Daniel,

MrDMurray commented 6 years ago

-You can probably use a piece of White Styrofoam to make sure proper reflection occurs. + Yes exactly. In this case the water was actually so dirty that a good amount of reflection happened. The second signal when you get it is actually very constant so should be easy to spot and have ignored

-What data does the Thingspeak upload? Is it the CSV file? If so, how does it receive the file in the code to upload to the web and how does the code create a CSV file:

writes this data to a table (a .csv file), this is needed for the graph with open("cpu_dists.csv", "a") as log: # "a" means append to the end log.write("{0},{1}\n".format(strftime("%Y-%m-%d %H:%M:%S"),str(mode))) and the function:

+Thingspeak is a webpage by the The MathWorks (famous for MATLAB) that lets you send data from a python program to their free data analytics service with just a few lines of code. (see the example here: https://github.com/STJRush/rpi/blob/master/webwatersensor/thingspeaktestpy3.py) You sign up with them, they give you an API key (a big long number) and you can choose any of your program's variables eg. distance, speed, mass, temperature and they do all the hard work of making it look nice on a graph. They even put it on a webpage for you with an iframe for embedding.

`def updateThingSpeak(): #sends data to a webpage print('starting...') baseURL = 'https://api.thingspeak.com/update?api_key=%s' % myAPI

try: print("The mode being sent to the web is " + str(mode) + "cm") f = urlopen(baseURL + "&field1=%s" % (str(mode))) print (f.read()) f.close() sleep(30) #uploads sensor values every 30 secs How does this for Loop, only take 10 Measurements if the variable is equal to 50?number_of_readings = 50 #how many readings to take and find the mode of

+ Sorry that's probably just not updated. I bumped it up to 50 to get a better mode.

for pizza in range(number_of_readings): #takes 10 readings distance = distcheck() #checks distance readings_list.append(int(distance)) #puts the 10 values in a list`

-Is this code for getting the mathematical mode of all the readings? Is this the figure going to be shown in the CSV file? print(readings_list) #prints the list and gets the mode (most common value) mode = max(set(readings_list), key=readings_list.count) print("The mode of " + str(number_of_readings) + " values is " + str(mode))

+Yes 50 readings go in a list and then python takes the mode (most common reading) from the list. The mode is what gets uploaded to the webpage graph as it is not affected by outliers .

-Finally, should the limit be the number the user inputted in the first place? It is set as <10 currently: limit=input("Set a limit in cm to trigger an email alert eg. 5 ") and if mode <10 and mailAlert == 1: #sends email if mode is <10cm send_mail_alert()

+Yes the water level warning will depend on what kind of water tank you are reading from. I just set it to something easy to check the code works alright. This indeed could be a user input. I'll bring this in tomorrow for coding club.

There is loads of cool things in the code that will help u

daniel-obrien commented 6 years ago

??


From: Daniel Murray notifications@github.com Sent: Sunday, February 18, 2018 10:45:38 PM To: STJRush/rpi Cc: Subscribed Subject: Re: [STJRush/rpi] WaterTankSensor Questions (#11)

-You can probably use a piece of White Styrofoam to make sure proper reflection occurs.

-What data does the Thingspeak upload? Is it the CSV file? If so, how does it receive the file in the code to upload to the web and how does the code create a CSV file:

writes this data to a table (a .csv file), this is needed for the graph with open("cpu_dists.csv", "a") as log: # "a" means append to the end log.write("{0},{1}\n".format(strftime("%Y-%m-%d %H:%M:%S"),str(mode))) and the function:

+Thingspeak is a webpage by the The MathWorks (famous for MATLAB) that lets you send data from a python program to their free data analytics service with just a few lines of code. (see the example here: https://github.com/STJRush/rpi/blob/master/webwatersensor/thingspeaktestpy3.pyhttps://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FSTJRush%2Frpi%2Fblob%2Fmaster%2Fwebwatersensor%2Fthingspeaktestpy3.py&data=02%7C01%7C%7C714ae238fc1c47a680b108d5772155b5%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636545907404383078&sdata=aA%2FuHyNzEpHVvKfpR8iADMEIacIDRC%2Bt5Wj7LZkP8hE%3D&reserved=0) You sign up with them, they give you an API key (a big long number) and you can choose any of your program's variables eg. distance, speed, mass, temperature and they do all the hard work of making it look nice on a graph. They even put it on a webpage for you with an iframe for embedding.

`def updateThingSpeak(): #sends data to a webpage print('starting...') baseURL = 'https://api.thingspeak.com/update?api_key=%shttps://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fapi.thingspeak.com%2Fupdate%3Fapi_key%3D%25s&data=02%7C01%7C%7C714ae238fc1c47a680b108d5772155b5%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636545907404383078&sdata=aPkxSkFQN%2FPscNRPLLWsk6bgYI0shn7Ce8VYpOLbiPI%3D&reserved=0' % myAPI

try: print("The mode being sent to the web is " + str(mode) + "cm") f = urlopen(baseURL + "&field1=%s" % (str(mode))) print (f.read()) f.close() sleep(30) #uploads sensor values every 30 secsHow does this for Loop, only take 10 Measurements if the variable is equal to 50?number_of_readings = 50 #how many readings to take and find the mode of

for pizza in range(number_of_readings): #takes 10 readings distance = distcheck() #checks distance readings_list.append(int(distance)) #puts the 10 values in a list`

-Is this code for getting the mathematical mode of all the readings? Is this the figure going to be shown in the CSV file? print(readings_list) #prints the list and gets the mode (most common value) mode = max(set(readings_list), key=readings_list.count) print("The mode of " + str(number_of_readings) + " values is " + str(mode))

+Yes 50 readings go in a list and then python takes the mode (most common reading) from the list. The mode is what gets uploaded to the webpage graph as it is not affected by outliers .

-Finally, should the limit be the number the user inputted in the first place? It is set as <10 currently: limit=input("Set a limit in cm to trigger an email alert eg. 5 ") and if mode <10 and mailAlert == 1: #sends email if mode is <10cm send_mail_alert()

+Yes the water level warning will depend on what kind of water tank you are reading from. I just set it to something easy to check the code works alright. This indeed could be a user input. I'll bring this in tomorrow for coding club.

There is loads of cool things in the code that will help u

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FSTJRush%2Frpi%2Fissues%2F11%23issuecomment-366555073&data=02%7C01%7C%7C714ae238fc1c47a680b108d5772155b5%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636545907404383078&sdata=ITBWkcKStul4PHX2xmf7I6S80Y3k55pewTJYG0P6Qp4%3D&reserved=0, or mute the threadhttps://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAWE9GkWfvTPRqF1nEVvR7IMWwT534IEKks5tWKgSgaJpZM4SI704&data=02%7C01%7C%7C714ae238fc1c47a680b108d5772155b5%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636545907404383078&sdata=tfuaHxttJi33j2LL8lacqUuPnFQv%2B%2FhMcPiKHmTCS9E%3D&reserved=0.