Rich Noordam
Published © GPL3+

Raspberry Pi/WeatherRack - NodeJS Weather Data Station

Raspberry Pi, and a WeatherRack, with a WeatherPiArduino, using NodeJS to serve weather station current data.

IntermediateWork in progress16 hours4,102
Raspberry Pi/WeatherRack - NodeJS Weather Data Station

Things used in this project

Hardware components

Raspberry Pi 2 Model B
Raspberry Pi 2 Model B
×1
WeatherPiArduino
×1
WeatherRack
×1
AM2315 Temperature Sensor
×1
lightning sensor module
×1
ADS1015 12 bit ADC
×1

Software apps and online services

Raspian
NodeJS
Python

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Schematics

schematic from docs.

Code

myApp.js

JavaScript
file that handles how NodeJS runs
var cluster = require('cluster');
// this keeps things running if we have a failure.
if (cluster.isMaster) {
   var i = 0;
   for (i; i< 1; i++){
     cluster.fork();
   }
   //if the worker dies, restart it.
   cluster.on('exit', function(worker){
      console.log('Worker ' + worker.id + ' died..');
      cluster.fork();
   });
} else {
var PythonShell = require('python-shell');
var express = require('express');
var app = express();

app.get('/TemperatureF', function(req, res) {
	var pyshell = new PythonShell('TemperatureF.py');
	pyshell.on('message', function(message) {
		console.log(message);
		res.send(message);
	})
})

app.get('/TemperatureC', function(req, res) {
	var pyshell = new PythonShell('TemperatureC.py');
	pyshell.on('message', function(message) {
		console.log(message);
		res.send(message);
	})
})

app.get('/PiBoxTemperature', function(req, res) {
	var pyshell = new PythonShell('PiBoxTemperature.py');
	pyshell.on('message', function(message) {
		console.log(message);
		res.send(message);
	})
})


app.get('/Humidity', function(req, res) {
	var pyshell = new PythonShell('Humidity.py');
	pyshell.on('message', function(message) {
		console.log(message);
		res.send(message);
	})
})

app.get('/Pressure', function(req, res) {
	var pyshell = new PythonShell('Pressure.py');
	pyshell.on('message', function(message) {
		console.log(message);
		res.send(message);
	})
})

app.get('/Rain', function(req, res) {
	var pyshell = new PythonShell('Rain.py');
	pyshell.on('message', function(message) {
		console.log(message);
		res.send(message);
	})
})

app.get('/WindDirection', function(req, res) {
	var pyshell = new PythonShell('WindDirection.py');
	pyshell.on('message', function(message) {
		console.log(message);
		res.send(message);
	})
})

app.get('/WindSpeed', function(req, res) {
	var pyshell = new PythonShell('WindSpeed.py');
	pyshell.on('message', function(message) {
		console.log(message);
		res.send(message);
	})
})

app.get('/WindGusts', function(req, res) {
	var pyshell = new PythonShell('WindGust.py');
	pyshell.on('message', function(message) {
		console.log(message);
		res.send(message);
	})
})

port = '8080';
host = '192.168.1.200';

var server = app.listen(port, host)
console.log("App Listening on @ http://%s:%s", host, port)

}

WindGust.py

Python
import sys
import RPi.GPIO as GPIO
import spidev

GPIO.setmode(GPIO.BCM)

sys.path.append('../Adafruit_Python_GPIO')
#sys.path.append('../SDL_Pi_Weather_80422')

import SDL_Pi_Weather_80422 as SDL_Pi_Weather_80422


#WeatherRack Weather Sensors
#
# GPIO Numbering Mode GPIO.BCM
#

anenometerPin = 23
rainPin = 24

# constants
SDL_MODE_INTERNAL_AD = 0
SDL_MODE_I2C_ADS1015 = 1

#sample mode means return immediately.  THe wind speed is averaged at sampleTime or when yo$
SDL_MODE_SAMPLE = 0
#Delay mode means to wait for sampleTime and the average after that time.
SDL_MODE_DELAY = 1

weatherStation = SDL_Pi_Weather_80422.SDL_Pi_Weather_80422(anenometerPin, rainPin, 0,0, SDL_MODE_I2C_ADS1015)

weatherStation.setWindMode(SDL_MODE_SAMPLE, 5.0)
#weatherStation.setWindMode(SDL_MODE_DELAY, 5.0)



def setSensorOutput():
     global outputString
     outputString = ""
     # do Wind Gust
     currentWindGust = weatherStation.get_wind_gust()/1.6
     outputString = "{:00.2f}".format(currentWindGust)

try:
	setSensorOutput()
	print outputString
except:
	pass

WindSpeed.py

Python
import sys
import RPi.GPIO as GPIO
import spidev

GPIO.setmode(GPIO.BCM)

sys.path.append('../Adafruit_Python_GPIO')
#sys.path.append('../SDL_Pi_Weather_80422')

import SDL_Pi_Weather_80422 as SDL_Pi_Weather_80422


#WeatherRack Weather Sensors
#
# GPIO Numbering Mode GPIO.BCM
#

anenometerPin = 23
rainPin = 24

# constants
SDL_MODE_INTERNAL_AD = 0
SDL_MODE_I2C_ADS1015 = 1

#sample mode means return immediately.  THe wind speed is averaged at sampleTime or when yo$
SDL_MODE_SAMPLE = 0
#Delay mode means to wait for sampleTime and the average after that time.
SDL_MODE_DELAY = 1

weatherStation = SDL_Pi_Weather_80422.SDL_Pi_Weather_80422(anenometerPin, rainPin, 0,0, SDL_MODE_I2C_ADS1015)

weatherStation.setWindMode(SDL_MODE_SAMPLE, 5.0)
#weatherStation.setWindMode(SDL_MODE_DELAY, 5.0)

def setSensorOutput():
     global outputString
     outputString = ""
     # do Wind Speed
     currentWindSpeed = weatherStation.current_wind_speed()/1.6
     currWindSpeed = "{:.2f}".format(currentWindSpeed)
     outputString = currWindSpeed

try:
	setSensorOutput()
	print outputString
except:
	pass

Humidity.py

Python
import sys
import RPi.GPIO as GPIO
import spidev

GPIO.setmode(GPIO.BCM)
sys.path.append('./Adafruit_Python_GPIO')

################
from tentacle_pi.AM2315 import AM2315
am = AM2315(0x5c,"/dev/i2c-1")


def setSensorOutput():
     global outputString
     outputString = ""
     temperature, humidity, crc_check = am.sense()
     outputString = "{:.2f}".format(humidity)

try:    
	setSensorOutput()
	print outputString
except:
	pass

PiBoxTemperature

Python
temperature of enclosure
import sys
import RPi.GPIO as GPIO
import spidev

GPIO.setmode(GPIO.BCM)

sys.path.append('../Adafruit_Python_BMP')
sys.path.append('../Adafruit_Python_GPIO')

import Adafruit_BMP.BMP085 as BMP180

# BMP180 Setup (compatible with BMP085)

bmp180 = BMP180.BMP085()

################

def setSensorOutput():
     global outputString
     outputString = ""
     # do BMP180 temperature
     outputString = "{:.2f}".format(bmp180.read_temperature())

try:   
	outputString = ""
	setSensorOutput()
	print outputString
except:
	pass

Pressure.py

Python
import sys
import RPi.GPIO as GPIO
import spidev

GPIO.setmode(GPIO.BCM)

sys.path.append('../RTC_SDL_DS3231')
sys.path.append('../Adafruit_Python_BMP')
sys.path.append('../Adafruit_Python_GPIO')
sys.path.append('../SDL_Pi_FRAM')

import Adafruit_BMP.BMP085 as BMP180

# BMP180 Setup (compatible with BMP085)

bmp180 = BMP180.BMP085()

################

def setSensorOutput():
     global outputString
     outputString = ""
     # do BMP180 temperature
     outputString = "{:.2f}".format(bmp180.read_pressure()/1000)

try:    
	outputString = ""
	setSensorOutput()
	print outputString
except:
	pass

Rain.py

Python
import sys
import RPi.GPIO as GPIO
import spidev

GPIO.setmode(GPIO.BCM)

sys.path.append('../Adafruit_Python_GPIO')
#sys.path.append('../SDL_Pi_Weather_80422')

import SDL_Pi_Weather_80422 as SDL_Pi_Weather_80422


#WeatherRack Weather Sensors
#
# GPIO Numbering Mode GPIO.BCM
#

anenometerPin = 23
rainPin = 24

# constants
SDL_MODE_INTERNAL_AD = 0
SDL_MODE_I2C_ADS1015 = 1

#sample mode means return immediately.  THe wind speed is averaged at sampleTime or when yo$
SDL_MODE_SAMPLE = 0
#Delay mode means to wait for sampleTime and the average after that time.
SDL_MODE_DELAY = 1

weatherStation = SDL_Pi_Weather_80422.SDL_Pi_Weather_80422(anenometerPin, rainPin, 0,0, SDL_MODE_I2C_ADS1015)

weatherStation.setWindMode(SDL_MODE_SAMPLE, 5.0)
#weatherStation.setWindMode(SDL_MODE_DELAY, 5.0)

def setSensorOutput():
     global outputString
     outputString = ""
     # do Rain Total
     totalRain = weatherStation.get_current_rain_total()/25.4
     outputString = "{:.2f}".format(totalRain)

try:    
	setSensorOutput()
	print outputString
except:
	pass

TemperatureC.py

Python
import sys
import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BCM)
sys.path.append('./Adafruit_Python_GPIO')

################
from tentacle_pi.AM2315 import AM2315
am = AM2315(0x5c,"/dev/i2c-1")


def setSensorOutput():
     global outputString
     outputString = ""
     temperature, humidity, crc_check = am.sense()
     outputString = "{:.1f}".format(temperature)
    
try:
	setSensorOutput()
	print outputString
except:
	pass

TemperatureF.py

Python
import sys
import RPi.GPIO as GPIO
import spidev

GPIO.setmode(GPIO.BCM)
sys.path.append('./Adafruit_Python_GPIO')

################
from tentacle_pi.AM2315 import AM2315
am = AM2315(0x5c,"/dev/i2c-1")


def setSensorOutput():
     global outputString
     outputString = ""
     temperature, humidity, crc_check = am.sense()
     outputString = "{:.2f}".format(temperature)
    
try:
	setSensorOutput()
	holder = (float(outputString) * 1.8)+ 32
	outputString = "{:.1f}".format(holder)
	print outputString
except:
	pass

WindDirection.py

Python
import sys
import RPi.GPIO as GPIO
import spidev

GPIO.setmode(GPIO.BCM)

sys.path.append('../Adafruit_Python_GPIO')
#sys.path.append('../SDL_Pi_Weather_80422')

import SDL_Pi_Weather_80422 as SDL_Pi_Weather_80422

#WeatherRack Weather Sensors
#
# GPIO Numbering Mode GPIO.BCM
#

anenometerPin = 23
rainPin = 24

# constants
SDL_MODE_INTERNAL_AD = 0
SDL_MODE_I2C_ADS1015 = 1

#sample mode means return immediately.  THe wind speed is averaged at sampleTime or when yo$
SDL_MODE_SAMPLE = 0
#Delay mode means to wait for sampleTime and the average after that time.
SDL_MODE_DELAY = 1

weatherStation = SDL_Pi_Weather_80422.SDL_Pi_Weather_80422(anenometerPin, rainPin, 0,0, SDL_MODE_I2C_ADS1015)

weatherStation.setWindMode(SDL_MODE_SAMPLE, 5.0)
#weatherStation.setWindMode(SDL_MODE_DELAY, 5.0)


################


def setWindDirection(degrees):
     global currDirection
     if degrees == "0.00":
	currDirection = "N"
     if degrees == "22.50":
        currDirection = "NNE"
     if degrees == "45.00":
        currDirection = "NE"
     if degrees == "67.50":
        currDirection = "ENE"
     if degrees == "90.00":
        currDirection = "E"
     if degrees == "112.50":
        currDirection = "ESE"
     if degrees == "135.00":
        currDirection = "SE"
     if degrees == "157.50":
        currDirection = "SSE"
     if degrees == "180.00":
        currDirection = "S"
     if degrees == "202.50":
        currDirection = "SSW"
     if degrees == "225.00":
        currDirection = "SW"
     if degrees == "247.50":
        currDirection = "WSW"
     if degrees == "270.00":
        currDirection = "W"
     if degrees == "292.50":
        currDirection = "WNW"
     if degrees == "315.00":
        currDirection = "NW"
     if degrees == "337.50":
        currDirection = "NNW"


def setSensorOutput():
     global currDirection
     # do Wind Direction
     windDegrees = "{:.2f}".format(weatherStation.current_wind_direction())
     setWindDirection(windDegrees)

try:    
	setSensorOutput()
	print currDirection
except:
	pass

WeatherPiArduino - Raspberry Pi code

WeatherRack Pi Repository

Credits

Rich Noordam

Rich Noordam

10 projects • 33 followers
Many interests, computing obviously being one of them. MS SQL Server Database Administration, Reporting, Data Science, and more.

Comments