La Crosse Weather Pro WS-1612AL-IT Weather Station
1. Connecting a raspberry pi to an arduino
First we downloaded the arduino software from arduino.cc using the Macs. We had to download the arduino environment and then connect the arduino to the Mac with a USB cord. We opened the arduino Application and tested the connection with the blink example. Once we uploaded the program the light on the arduino blinked every two seconds and we were successful.
Next, we plugged the arduino into the raspberry pi with a USB cord. Then we had to figure out how to get them to communicate. We found a MagPi issue (issue 7) which explained how to do this in the link: http://www.themagpi.com/issue/
We first had to install the Arduino IDE and Firmata which is the library for communicating with software on the host computer (in this case it is the raspberry pi). Then we had to install pyFirmata which allows Firmata to talk to Python and able to talk to the raspberry pi.
We also found a helpful link that had code that told the arduino to talk to the raspberry pi. Every two seconds, the arduino sent "Hello Pi" to the raspberry pi! This is the link we used for that: http://blog.oscarliang.net/
2. Arduino reading LM34 Sensor and sending temperature to raspberry pi
From the MagPi issue above, we were able to read the temperature from the LM34. The data sheet for this LM34 temperature sensor is: https://www.jameco.com/Jameco/
/*
Analog input, analog output, serial output
Reads an analog input pin, maps the result to a range from 0 to 255
and uses the result to set the pulsewidth modulation (PWM) of an output pin.
Also prints the results to the serial monitor.
The circuit:
* potentiometer connected to analog pin 0.
Center pin of the potentiometer goes to the analog pin.
side pins of the potentiometer go to +5V and ground
* LED connected from digital pin 9 to ground
created 29 Dec. 2008
modified 9 Apr 2012
by Tom Igoe
This example code is in the public domain.
*/
// These constants won't change. They're used to give names
// to the pins used:
const int analogInPin = A0; // Analog input pin that the
potentiometer is attached to
//const int analogOutPin = 9; // Analog output pin that the LED is attached to
int sensorValue = 0; // value read from the pot
double outputValue, voltage, temperature; // value output to
the PWM (analog out)
void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
}
void loop() {
// read the analog in value:
sensorValue = analogRead(analogInPin);
// map it to the range of the analog out:
//outputValue = map(sensorValue, 0, 1023, 0, 5.);
voltage = (sensorValue/ 1023.0) * 5.0;
// change the analog out value:
//analogWrite(analogOutPin, outputValue);
temperature = (voltage * 1000.0)/10.0;
// print the results to the serial monitor:
Serial.print("sensor = " );
Serial.print(sensorValue);
Serial.print("\t voltage = ");
Serial.print(voltage);
Serial.print("\t temperature = ");
Serial.println(temperature);
// wait 2 milliseconds before the next loop
// for the analog-to-digital converter to settle
// after the last reading:
delay(1000);
}
Analog input, analog output, serial output
Reads an analog input pin, maps the result to a range from 0 to 255
and uses the result to set the pulsewidth modulation (PWM) of an output pin.
Also prints the results to the serial monitor.
The circuit:
* potentiometer connected to analog pin 0.
Center pin of the potentiometer goes to the analog pin.
side pins of the potentiometer go to +5V and ground
* LED connected from digital pin 9 to ground
created 29 Dec. 2008
modified 9 Apr 2012
by Tom Igoe
This example code is in the public domain.
*/
// These constants won't change. They're used to give names
// to the pins used:
const int analogInPin = A0; // Analog input pin that the
potentiometer is attached to
//const int analogOutPin = 9; // Analog output pin that the LED is attached to
int sensorValue = 0; // value read from the pot
double outputValue, voltage, temperature; // value output to
the PWM (analog out)
void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
}
void loop() {
// read the analog in value:
sensorValue = analogRead(analogInPin);
// map it to the range of the analog out:
//outputValue = map(sensorValue, 0, 1023, 0, 5.);
voltage = (sensorValue/ 1023.0) * 5.0;
// change the analog out value:
//analogWrite(analogOutPin, outputValue);
temperature = (voltage * 1000.0)/10.0;
// print the results to the serial monitor:
Serial.print("sensor = " );
Serial.print(sensorValue);
Serial.print("\t voltage = ");
Serial.print(voltage);
Serial.print("\t temperature = ");
Serial.println(temperature);
// wait 2 milliseconds before the next loop
// for the analog-to-digital converter to settle
// after the last reading:
delay(1000);
}
3. Hooking DHT22 sensor to an arduino and reading data on raspberry pi
This sensor measures temperature and humidity and the data sheet can be found on the following link:
http://www.adafruit.com/datasheets/Digital%20humidity%20and%20temperature%20sensor%20AM2302.pdf
To hook the sensor up to an arduino board we followed this picture:
Here is the link explaining how to hook these up: https://learn.adafruit.com/dht/connecting-to-a-dhtxx-sensor
Now that we had the sensor hooked up, we found a code for the arduino IDE that would read the data. This was also found on the adafruit website: https://learn.adafruit.com/dht/using-a-dhtxx-sensor
We had to download the DHT library and ran the DHTtester program from the examples in the arduino. We then edited this code to make it simpler. Here is the code that reads the temperature and humidity:
#include <SPI.h>
#include "DHT.h"
// DHT Sensor Setup
#define DHTPIN 2 // We have connected the DHT to Digital Pin 2
#define DHTTYPE DHT22 // This is the type of DHT Sensor (Change it to
DHT11 if you're using that model)
DHT dht(DHTPIN, DHTTYPE); // Initialize DHT object
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
dht.begin();
}
float h, t;
void loop() {
h = dht.readHumidity();
t = dht.readTemperature();
Serial.print(h);
Serial.print("\t");
Serial.println(t);
delay(10000);
}
#include "DHT.h"
// DHT Sensor Setup
#define DHTPIN 2 // We have connected the DHT to Digital Pin 2
#define DHTTYPE DHT22 // This is the type of DHT Sensor (Change it to
DHT11 if you're using that model)
DHT dht(DHTPIN, DHTTYPE); // Initialize DHT object
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
dht.begin();
}
float h, t;
void loop() {
h = dht.readHumidity();
t = dht.readTemperature();
Serial.print(h);
Serial.print("\t");
Serial.println(t);
delay(10000);
}
4. Uploading the data from DHT22 sensor onto plotly
Now that we got the information reading from the DHT sensor, we found a way to put temperature and humidity onto graphs and accessible through the internet. There are many different ways to approach this but we decided to use plotly to stream the data and update it. First we set up a plotly account on: https://plot.ly/
The username and password for this account is the same for the Siena Physics computers (username=physuser).
We then made a code that sent temperature in Fahrenheit, humidity, and temperature in Celsius to plotly in a single graph. The following code goes in the raspberry pi terminal with the command "./filename" with the filename including the python code below:
#!/usr/bin/python
import plotly.plotly as py
import time
import datetime
import serial
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')
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) #update every 5 seconds
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/
5. Reading data from the weather station using an arduino and RFM transceiver circuit
We found a link that would help us connect the La Crosse Weather Pro to the arduino using a RFM12B transceiver. This is the link: http://nikseresht.com/blog/?p=99
Below is the picture on that website that we had to follow and then the actual circuit that we built. We had to solder wires to the RFM transceiver. We also added an antennae that is 7.8cm long because the wavelength that we are trying to receive is 915MHz. This is the link we used to determine the length of the antennae:
http://openenergymonitor.org/emon/buildingblocks/rfm12b-wireless
To make the arduino read signals from the weather station, we used the code on this link:
http://nikseresht.com/blog/wp-content/uploads/2013/09/lacrosse_recv_915.txt
We changed a few things such as the Baud Rate to 9600 and changed the way the data was displayed. Here is what the final code that works looks like:
// Tested with Arduino 1.05
// polling RFM12B to decode FSK iT+ with a Jeenode from Jeelabs.
// Arduino UNO + RFM12B Module
// device
// : IT+ TX22U-IT LA Crosse Technology (c) USA
// info : http://www.g-romahn.de/ws1600/ Datepakete_raw.txt
// http://forum.jeelabs.net/node/ 110
// http://fredboboss.free.fr/ tx29/tx29_sw.php
// http://www.f6fbb.org/domo/ sensors/
// http://www.mikrocontroller. net/topic/67273 benedikt.k org
// rinie,marf,joop,Mohammad 23 Aug 2013
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#define clrb(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#define setb(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#define RF_PORT PORTB
#define RF_DDR DDRB
#define RF_PIN PINB
#define SDI 3 // polling 4 Pins ,3 SPI + Chipselect
#define SCK1 5 // differs with Jee-node lib !
#define CS 2
#define SDO 4
// ****************************** ****************************** *******************
static uint8_t quartets[26];
void setup ()
{
Serial.begin(9600);
rf12_la_init();
}
void loop ()
{
rf12_xfer(0xA534);
receive();
rf12_xfer(0xA7d0);
receive();
rf12_xfer(0xAA6b);
receive();
}
void receive(void)
{ unsigned char test[13];
uint8_t i,temp;
rf12_rxdata(test,13);
for(i = 0; i<13; i++){
temp = test[i];
quartets[2*i+1]= temp & 0b00001111;
quartets[2*i]= (temp>>4) & 0b00001111;
}
display_values();
Serial.println();
}
void rf12_rxdata(unsigned char *data, unsigned char number)
{ uint8_t i;
rf12_xfer(0x82C8); // receiver on
rf12_xfer(0xCA81); // set FIFO mode
rf12_xfer(0xCA83); // enable FIFO
for (i=0; i<number; i++)
{ rf12_ready();
*data++=rf12_xfer(0xB000);
}
rf12_xfer(0x8208); // Receiver off
}
// ******** SPI + RFM 12B functions ****************************** ************
unsigned short rf12_xfer(unsigned short value)
{ uint8_t i;
clrb(RF_PORT, CS);
for (i=0; i<16; i++)
{ if (value&32768)
setb(RF_PORT, SDI);
else
clrb(RF_PORT, SDI);
value<<=1;
if (RF_PIN&(1<<SDO))
value|=1;
setb(RF_PORT, SCK1);
asm("nop");
asm("nop");
clrb(RF_PORT, SCK1);
}
setb(RF_PORT, CS);
return value;
}
void rf12_ready(void)
{
clrb(RF_PORT, CS);
asm("nop");
asm("nop");
while (!(RF_PIN&(1<<SDO))); // wait until FIFO ready
setb(RF_PORT, CS);
}
static void rf12_la_init()
{
RF_DDR=(1<<SDI)|(1<<SCK1)|(1<< CS);
RF_PORT=(1<<CS);
for (uint8_t i=0; i<10; i++) _delay_ms(10); // wait until POR done
rf12_xfer(0x80f7); // 80e8 CONFIGURATION EL,EF,868 band,12.0pF //
iT+ 915 80f7
rf12_xfer(0xA534); // a67c FREQUENCY SETTING 909.99//
rf12_xfer(0xC627); // c627 DATA RATE 8.621 kbps
rf12_xfer(0xC26a); // c26a DATA FILTER COMMAND
rf12_xfer(0xCA12); // ca12 FIFO AND RESET 8,SYNC,!ff,DR
rf12_xfer(0xCEd4); // ced4 SYNCHRON PATTERN 0x2dd4
rf12_xfer(0xC49f); // c49f AFC during VDI HIGH +15 -15 AFC_control_commAND
rf12_xfer(0x95c0); // 95c0 RECEIVER CONTROL VDI Medium 67khz LNA max
DRRSI 103 dbm
rf12_xfer(0xCC77); // cc77 not in RFM01
rf12_xfer(0x9872); // 9872 transmitter not checked
rf12_xfer(0xE000); // e000 NOT USE
rf12_xfer(0xC800); // c800 NOT USE
rf12_xfer(0xC040); // c040 1.66MHz,2.2V
}
void display_values(void)
{
int temp;
uint8_t i;
if ( (quartets[0] != 0xa) ) return; // if bad data no display
for ( i = 1; i < quartets[3]+1; i++) {
switch( quartets[i*4] ) {
case 0:
//temperature
temp = (quartets[i*4+1]*100 + quartets[i*4+2]*10 + quartets[i*4+3])-400;
Serial.print(temp/10);
Serial.print(".");
Serial.print(quartets[i*4+3], HEX);
Serial.print("\t");
break;
case 1:
//humidity
Serial.print("\t");
Serial.print(quartets[i*4+2], HEX);
Serial.print(quartets[i*4+3], HEX);
Serial.print(" ");
Serial.print("\t");
Serial.print("\t");
break;
case 2:
//Rain
temp = ( quartets[i*4+3] + (quartets[i*4+2]<<4) +
((int)quartets[i*4+1]<<8) )*0.5;
Serial.print(temp);
Serial.print("\t");
Serial.print("\t");
break;
case 3:
//Wind
temp = ( quartets[i*4+3] + (quartets[i*4+2]<<4) );
Serial.print(temp);
Serial.print("\t");
Serial.print("\t");
//Wind Direction
temp = (quartets[i*4+1]*225/10);
Serial.print(temp);
Serial.print("\t");
Serial.print("\t");
break;
case 4:
//Gust
temp = ( quartets[i*4+3] + (quartets[i*4+2]<<4) +
((int)quartets[i*4+1]<<8) )*36/10;
Serial.print(temp);
break;
}
}
}
Finally we have the data streaming to the internet! This is what it looks like on plotly:
Below is the picture on that website that we had to follow and then the actual circuit that we built. We had to solder wires to the RFM transceiver. We also added an antennae that is 7.8cm long because the wavelength that we are trying to receive is 915MHz. This is the link we used to determine the length of the antennae:
http://openenergymonitor.org/emon/buildingblocks/rfm12b-wireless
To make the arduino read signals from the weather station, we used the code on this link:
http://nikseresht.com/blog/wp-content/uploads/2013/09/lacrosse_recv_915.txt
We changed a few things such as the Baud Rate to 9600 and changed the way the data was displayed. Here is what the final code that works looks like:
// Tested with Arduino 1.05
// polling RFM12B to decode FSK iT+ with a Jeenode from Jeelabs.
// Arduino UNO + RFM12B Module
// device
// : IT+ TX22U-IT LA Crosse Technology (c) USA
// info : http://www.g-romahn.de/ws1600/
// http://forum.jeelabs.net/node/
// http://fredboboss.free.fr/
// http://www.f6fbb.org/domo/
// http://www.mikrocontroller.
// rinie,marf,joop,Mohammad 23 Aug 2013
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#define clrb(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#define setb(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#define RF_PORT PORTB
#define RF_DDR DDRB
#define RF_PIN PINB
#define SDI 3 // polling 4 Pins ,3 SPI + Chipselect
#define SCK1 5 // differs with Jee-node lib !
#define CS 2
#define SDO 4
// ******************************
static uint8_t quartets[26];
void setup ()
{
Serial.begin(9600);
rf12_la_init();
}
void loop ()
{
rf12_xfer(0xA534);
receive();
rf12_xfer(0xA7d0);
receive();
rf12_xfer(0xAA6b);
receive();
}
void receive(void)
{ unsigned char test[13];
uint8_t i,temp;
rf12_rxdata(test,13);
for(i = 0; i<13; i++){
temp = test[i];
quartets[2*i+1]= temp & 0b00001111;
quartets[2*i]= (temp>>4) & 0b00001111;
}
display_values();
Serial.println();
}
void rf12_rxdata(unsigned char *data, unsigned char number)
{ uint8_t i;
rf12_xfer(0x82C8); // receiver on
rf12_xfer(0xCA81); // set FIFO mode
rf12_xfer(0xCA83); // enable FIFO
for (i=0; i<number; i++)
{ rf12_ready();
*data++=rf12_xfer(0xB000);
}
rf12_xfer(0x8208); // Receiver off
}
// ******** SPI + RFM 12B functions ******************************
unsigned short rf12_xfer(unsigned short value)
{ uint8_t i;
clrb(RF_PORT, CS);
for (i=0; i<16; i++)
{ if (value&32768)
setb(RF_PORT, SDI);
else
clrb(RF_PORT, SDI);
value<<=1;
if (RF_PIN&(1<<SDO))
value|=1;
setb(RF_PORT, SCK1);
asm("nop");
asm("nop");
clrb(RF_PORT, SCK1);
}
setb(RF_PORT, CS);
return value;
}
void rf12_ready(void)
{
clrb(RF_PORT, CS);
asm("nop");
asm("nop");
while (!(RF_PIN&(1<<SDO))); // wait until FIFO ready
setb(RF_PORT, CS);
}
static void rf12_la_init()
{
RF_DDR=(1<<SDI)|(1<<SCK1)|(1<<
RF_PORT=(1<<CS);
for (uint8_t i=0; i<10; i++) _delay_ms(10); // wait until POR done
rf12_xfer(0x80f7); // 80e8 CONFIGURATION EL,EF,868 band,12.0pF //
iT+ 915 80f7
rf12_xfer(0xA534); // a67c FREQUENCY SETTING 909.99//
rf12_xfer(0xC627); // c627 DATA RATE 8.621 kbps
rf12_xfer(0xC26a); // c26a DATA FILTER COMMAND
rf12_xfer(0xCA12); // ca12 FIFO AND RESET 8,SYNC,!ff,DR
rf12_xfer(0xCEd4); // ced4 SYNCHRON PATTERN 0x2dd4
rf12_xfer(0xC49f); // c49f AFC during VDI HIGH +15 -15 AFC_control_commAND
rf12_xfer(0x95c0); // 95c0 RECEIVER CONTROL VDI Medium 67khz LNA max
DRRSI 103 dbm
rf12_xfer(0xCC77); // cc77 not in RFM01
rf12_xfer(0x9872); // 9872 transmitter not checked
rf12_xfer(0xE000); // e000 NOT USE
rf12_xfer(0xC800); // c800 NOT USE
rf12_xfer(0xC040); // c040 1.66MHz,2.2V
}
void display_values(void)
{
int temp;
uint8_t i;
if ( (quartets[0] != 0xa) ) return; // if bad data no display
for ( i = 1; i < quartets[3]+1; i++) {
switch( quartets[i*4] ) {
case 0:
//temperature
temp = (quartets[i*4+1]*100 + quartets[i*4+2]*10 + quartets[i*4+3])-400;
Serial.print(temp/10);
Serial.print(".");
Serial.print(quartets[i*4+3],
Serial.print("\t");
break;
case 1:
//humidity
Serial.print("\t");
Serial.print(quartets[i*4+2],
Serial.print(quartets[i*4+3],
Serial.print(" ");
Serial.print("\t");
Serial.print("\t");
break;
case 2:
//Rain
temp = ( quartets[i*4+3] + (quartets[i*4+2]<<4) +
((int)quartets[i*4+1]<<8) )*0.5;
Serial.print(temp);
Serial.print("\t");
Serial.print("\t");
break;
case 3:
//Wind
temp = ( quartets[i*4+3] + (quartets[i*4+2]<<4) );
Serial.print(temp);
Serial.print("\t");
Serial.print("\t");
//Wind Direction
temp = (quartets[i*4+1]*225/10);
Serial.print(temp);
Serial.print("\t");
Serial.print("\t");
break;
case 4:
//Gust
temp = ( quartets[i*4+3] + (quartets[i*4+2]<<4) +
((int)quartets[i*4+1]<<8) )*36/10;
Serial.print(temp);
break;
}
}
}
6. Putting the data from the weather station onto plotly
To get the weather data that is appearing in the serial monitor to plotly, we modified the code from step 4. We had to add more code because the weather station has 6 columns of data in the serial monitor rather than 2 like the DHT sensor. The following code is what actually put temperature, humidity, rain, wind speed, wind direction and gust onto on plot in plotly:
#!/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()
temp_C = float(data[0])
humidity = float(data[1])
rain = float(data[2])
windDc = float(data[3])
windDir = float(data[4])
gustDc = float(data[5])
# convert celsius to fahrenheit
temperature = ( temp_C * 9.0 / 5.0 ) + 32
#convert wind deci meters to meters
wind = windDc/10
gust = gustDc/10
date_stamp = datetime.datetime.now()
return date_stamp,temperature, humidity,rain,wind,windDir, gust
ser = serial.Serial('/dev/ttyACM0', 9600)
py.sign_in('physuser',' aldyw0r26q')
x1=[]
x2=[]
x3=[]
y1=[]
y2=[]
y3=[]
x4=[]
x5=[]
x6=[]
y4=[]
y5=[]
y6=[]
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 = 'Rain')
#data=Data([my_data1,my_data2, my_data3])
my_data4 = Scatter(x=x4,y=y4,
stream=dict(token='onmmq775to' ),xaxis='x4',yaxis='y4', name = 'Wind
Speed')
#data=Data([my_data1,my_data2, my_data3])
my_data5 = Scatter(x=x5,y=y5,
stream=dict(token='g97c3g3475' ),xaxis='x5',yaxis='y5', name = 'Wind
direction')
#data=Data([my_data1,my_data2, my_data3])
my_data6 = Scatter(x=x6,y=y6,
stream=dict(token='6l3o4sttj6' ),xaxis='x6',yaxis='y6', name = 'Gust')
data=Data([my_data1,my_data2, my_data3,my_data4,my_data5,my_ data6])
layout=Layout(title='Siena
Weather',xaxis1=XAxis(anchor=' y1',title='time',showline= True),yaxis=YAxis(domain=[0,. 12],title='Temperature(Degrees
F)',showline=True),xaxis2= XAxis(anchor='y2',title='time' ,showline=True),yaxis2=YAxis( domain=[0.18,0.30],title=' Relative
Humidity(%)',showline=True), xaxis3=XAxis(anchor='y3', title='time',showline=True), yaxis3=YAxis(domain=[0.36,0. 48],title='Rain',showline= True),
xaxis4=XAxis(anchor='y4', title='yaxis4=YAxis(domain=[0. 53,0.65],title='Wind
Speed(m/s)',showline=True), xaxis5=XAxis(anchor='y5', title='time',showline=True), yaxis5=YAxis(domain=[0.71,0. 83],title='Wind
Direction(Degrees)',showline= True),xaxis6=XAxis(anchor='y6' ,title='time',showline=True), yaxis6=YAxis(domain=[0.89,1], title='Gust(m/s)',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')
s4 = py.Stream('onmmq775to')
s5 = py.Stream('g97c3g3475')
s6 = py.Stream('6l3o4sttj6')
s1.open()
s2.open()
s3.open()
s4.open()
s5.open()
s6.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]))
s4.write(dict(x=pt[0], y=pt[4] ))
s5.write(dict(x=pt[0], y=pt[5]))
s6.write(dict(x=pt[0], y=pt[6]))
time.sleep(5)
s1.close()
s2.close()
s3.close()
s4.close()
s5.close()
s6.close()
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()
temp_C = float(data[0])
humidity = float(data[1])
rain = float(data[2])
windDc = float(data[3])
windDir = float(data[4])
gustDc = float(data[5])
# convert celsius to fahrenheit
temperature = ( temp_C * 9.0 / 5.0 ) + 32
#convert wind deci meters to meters
wind = windDc/10
gust = gustDc/10
date_stamp = datetime.datetime.now()
return date_stamp,temperature,
ser = serial.Serial('/dev/ttyACM0',
py.sign_in('physuser','
x1=[]
x2=[]
x3=[]
y1=[]
y2=[]
y3=[]
x4=[]
x5=[]
x6=[]
y4=[]
y5=[]
y6=[]
my_data1 = Scatter(x=x1,y=y1, stream=dict(token='tvfuqv0s6g'
my_data2 = Scatter(x=x2,y=y2,
stream=dict(token='bjo44dghec'
'Humidity')
#data=Data([my_data1,my_data2]
my_data3 = Scatter(x=x3,y=y3,
stream=dict(token='4tv7be960v'
#data=Data([my_data1,my_data2,
my_data4 = Scatter(x=x4,y=y4,
stream=dict(token='onmmq775to'
Speed')
#data=Data([my_data1,my_data2,
my_data5 = Scatter(x=x5,y=y5,
stream=dict(token='g97c3g3475'
direction')
#data=Data([my_data1,my_data2,
my_data6 = Scatter(x=x6,y=y6,
stream=dict(token='6l3o4sttj6'
data=Data([my_data1,my_data2,
layout=Layout(title='Siena
Weather',xaxis1=XAxis(anchor='
F)',showline=True),xaxis2=
Humidity(%)',showline=True),
xaxis4=XAxis(anchor='y4',
Speed(m/s)',showline=True),
Direction(Degrees)',showline=
width=900, height = 1200, autosize=False)
my_fig1=Figure(data=data,
py.plot(my_fig1, auto_open = False)
s1 = py.Stream('tvfuqv0s6g')
s2 = py.Stream('bjo44dghec')
s3 = py.Stream('4tv7be960v')
s4 = py.Stream('onmmq775to')
s5 = py.Stream('g97c3g3475')
s6 = py.Stream('6l3o4sttj6')
s1.open()
s2.open()
s3.open()
s4.open()
s5.open()
s6.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]))
s4.write(dict(x=pt[0], y=pt[4] ))
s5.write(dict(x=pt[0], y=pt[5]))
s6.write(dict(x=pt[0], y=pt[6]))
time.sleep(5)
s1.close()
s2.close()
s3.close()
s4.close()
s5.close()
s6.close()
Finally we have the data streaming to the internet! This is what it looks like on plotly:




No comments:
Post a Comment