Coder Social home page Coder Social logo

garni's Introduction

Garni Weather Station server PHP script

This simple php script gets data values from your Garni Meteo Station and converts everything to JSON file on your server. You need to setup few things before start.

Requirements

  • linux php webhosting with any domain (I did not test IP address version and also windows server with php)
  • php 5.3+ (tested on 5.6, 7.1)
  • ftp connection to your server (you also need ftp client, or Total Commander)

Instalation

In your Garni device, you should add your domain where you will save you JSON file, for example myweb.com

  1. use ftp and connect to your server (domain myweb.com)
  2. make directory weatherstation in web root
  3. upload script updateweatherstation.php to /weatherstation directory
  4. make directory data in /weatherstation
  5. change /data directory attributes to 755 (chmod 755)

Testing

Check your php script if everything works OK. Go to your website in browser:

myweb.com/weatherstation/updateweatherstation.php

Now you should find file garni.json in data directory

myweb.com/weatherstation/data/garni.json

In garni.json file you should see these information

{"manufacturer":"Garni"}

Also, this is output of php script. You should see same information in your browser.

If you see correct testing information in browser and also in file, close your browser and never use testing URL again. Now, try start your Garni Meteo device and insert there correct domain name (only). You should see data values from your device in garni.json file.

Options

If you want switch off php output, please comment this line in php script

// echo $export;

Known bugs

  • there is problem if you use SSL (https) on your server. You need to use port 80 (http)
  • incorrect JSON headers in php output
  • in JSON file there are last data values, no history (but I can make it in future)

Future

  • local JSON history files
  • history data in SQL database
  • history data visualization

garni's People

Contributors

buffy007 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

garni's Issues

My setup

Hi, I made a similar script which puts the data into InfluxDB and then shows them in Grafana.

Php script:

<?php

# forward data to weatherunderground
$url = 'http://rtupdate.wunderground.com/weatherstation/updateweatherstation.php?' . http_build_query($_GET);
$result = file_get_contents($url);

# no need to save to file, but I like to see that the script works
file_put_contents('update', json_encode([$_GET, $result]));

# utility functions for unit conversion
function f2c($f) {
	return 5 / 9 * ($f - 32);
}
function in2hpa($in) {
	return $in * 33.86389;
}
function p2dec($p) {
	return $p / 100;
}
function mph2kmph($mph) {
	return $mph * 1.609344;
}
function in2mm($in) {
	return $in * 25.4;
}

function toInflux() {
	$barometric_pressure_hpa = in2hpa($_GET['baromin']);

	$temperature_c = f2c($_GET['tempf']);
	$humidity = $_GET['humidity'];
	$dew_point_c = f2c($_GET['dewptf']);

	$wind_speed_kmph = mph2kmph($_GET['windspeedmph']);
	$wind_gust_kmph = mph2kmph($_GET['windgustmph']);
	$wind_direction = $_GET['winddir'];

	$rain_mm = in2mm($_GET['rainin']);
	$daily_rain_mm = in2mm($_GET['dailyrainin']);

	$indoor_temperature_c = f2c($_GET['indoortempf']);
	$indoor_humidity = $_GET['indoorhumidity'];

	$content = [
		'barometric_pressure_hpa' => $barometric_pressure_hpa,
		'temperature_c' => $temperature_c,
		'humidity' => $humidity,
		'dew_point_c' => $dew_point_c,
		'wind_speed_kmph' => $wind_speed_kmph,
		'wind_gust_kmph' => $wind_gust_kmph,
		'wind_direction' => $wind_direction,
		'rain_mm' => $rain_mm,
		'daily_rain_mm' => $daily_rain_mm,
		'indoor_temperature_c' => $indoor_temperature_c,
		'indoor_humidity' => $indoor_humidity
	];

	$opts = [
		'http' => [
			'method' => "POST",
			'content' => "weather " . http_build_query($content, '', ','),
		]
	];

	$params = [
		"db" => "meteo"
	];

        # no need to store to file
	file_put_contents('influx', json_encode($opts));

	file_get_contents(
		'http://localhost:8086/write?' . http_build_query($params),
		false,
		stream_context_create($opts)
	);
}

toInflux();

docker-compose.yml:

version: '3'

services:
  influxdb:
    image: influxdb:1.8
    ports:
      - 8086:8086
    volumes:           
      - /srv/influxdvb:/var/lib/influxdb
  chronograf:
    image: chronograf:1.8
    ports:
      - 8888:8888
    environment:
      INFLUXDB_URL: http://influxdb:8086
  grafana:
    image: grafana/grafana:7.0.0
    ports:
      - 3000:3000
    volumes:
      - /srv/grafana:/var/lib/grafana

It would be easy to add php to the docker setup, I haven't done it yet.

The result can then look like this (grafana dashboard):
image

My setup does not include UV as my UV sensor is faulty and always reports 0. It would be very easy to add.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.