Today we started by testing the split method that is used to separate the line of data into two separate values. This works for the DHT sensor because there are only two values to read (temperature and humidity) but we needed to make sure that this would work with the weather station which has six different values. First we wrote a simple code using a string to test the split() method. We then wrote another simple code that read data from the serial monitor of the arduino. The values aren't coming in right because of the weather station.
We also worked on getting the streaming graphs from plotly to show up on one graph. We finally got three graphs to show up on one graph with the data from the DHT sensor which is shown below:
We used the same code that is on our previous blog for the arduino to read signals from the RFM transceiver. We had to change the code that goes in the raspberry pi terminal which is below:
#!/usr/bin/python
import plotly.plotly as py
import time
import datetime
import serial
#from plotly.graph_objs import Figure, Data,Scatter, Layout
from plotly.graph_objs import *
#reads the data from the sensors and splits the line into the correct variables
def getpoint(ser):
data = ser.readline().split()
humidity = float(data[0])
temp_C = float(data[1])
# convert celsius to fahrenheit
temperature = ( temp_C * 9.0 / 5.0 ) + 32
date_stamp = datetime.datetime.now()
return date_stamp,temperature,humidity,temp_C
# token info
ser = serial.Serial('/dev/ttyACM0',9600)
py.sign_in('physuser','aldyw0r26q')
x1=[]
x2=[]
x3=[]
y1=[]
y2=[]
y3=[]
my_data1 = Scatter(x=x1,y=y1, stream=dict(token='tvfuqv0s6g'), name ='Temp(F)')
my_data2 = Scatter(x=x2,y=y2,
stream=dict(token='bjo44dghec'),xaxis='x2',yaxis='y2', name =
'Humidity')
data=Data([my_data1,my_data2])
my_data3 = Scatter(x=x3,y=y3,
stream=dict(token='4tv7be960v'),xaxis='x3',yaxis='y3', name =
'Temp(C)')
data=Data([my_data1,my_data2,my_data3])
layout=Layout(title='Temp and
Humidity',xaxis1=XAxis(anchor='y1',title='time',showline=True),yaxis=YAxis(domain=[0,.20],title='Temperature(F)',showline=True),xaxis2=XAxis(anchor='y2',title='time',showline=True),yaxis2=YAxis(domain=[0.35,0.60],title='Humidity',showline=True),xaxis3=XAxis(anchor='y3',title='time',showline=True),yaxis3=YAxis(domain=[0.75,1],title='Temperature(C)',showline=True),
width=900, height = 1200, autosize=False)
my_fig1=Figure(data=data,layout=layout)
py.plot(my_fig1, auto_open = False)
s1 = py.Stream('tvfuqv0s6g')
s2 = py.Stream('bjo44dghec')
s3=py.Stream('4tv7be960v')
s1.open()
s2.open()
s3.open()
while True: #while loop for temperature
pt = getpoint(ser)
s1.write(dict(x=pt[0], y=pt[1] ))
s2.write(dict(x=pt[0], y=pt[2]))
s3.write(dict(x=pt[0], y=pt[3]))
time.sleep(5)
s1.close()
s2.close()
s3.close()
We used the following website to guide us into making these subplots: https://plot.ly/python/subplots/
We also added axes titles, black lines of the axes, changed the figure size and the size of each individual graph. These go under the layout section and we used this link: https://plot.ly/python/labels/
Now we need to figure out how to add three other plots onto this one graph because the weather station has six different values.
The time that shows up on the x-axis of the plotly graphs were in the wrong time zone. To fix this we had to change the time on the raspberry pi. First, you have to type in "sudo /usr/bin/raspi-config" in the raspberry pi terminal. We then clicked the "Internationalization options" and followed the simple steps to change the time zone. Now we have the correct time, but still in military time.