This repository was archived by the owner on Nov 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathatmosticker.php
160 lines (130 loc) · 4.15 KB
/
atmosticker.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<?php
/*
== ATMOCOM demo stickers ==
Renders a graphical sticker with current weather data, either in regular or minimal format depending on URL parameter
To draw regular, slightly larger sized sticker, call with 'sz=norm' or no URL parameter, e.g.:
http://mywebsite.com/atmocom/atmosticker.php
OR:
http://mywebsite.com/atmocom/atmosticker.php?sz=norm
To draw a smaller, minimalistic sticker, call with 'sz=mini', e.g.:
http://mywebsite.com/atmocom/atmosticker.php?sz=mini
This is the main script which include sticker specific drawing code
depending on URL parameter. Main scriptis dependent of agfx_mini.php
and agfx_norm.php scripts which must exist in the same folder.
MIT License, see repo for specifics.
This code is provided as is with no warranties or support.
Tntended for ATMOCOM proof-of-concept and demonstration purposes only.
Permission is hereby given to hack up, alter, re-invent or mutate as required.
Original script (c)2018 Astrogenic Systems
*/
if (array_key_exists('sz', $_REQUEST)) $size=$_REQUEST['sz'];
else $size='norm';
//Check that URL parameter is valid
if($size !== 'norm' && $size !== 'mini') die();
$dataFolder = 'wxdb/';
$dbFile = $dataFolder . 'wx'. date('Ym'). '.db';
//Common font
$font1 = 'res/Roboto-Black.ttf';
//Secondary font is based selected sticker size
if($size === 'mini')
$font2 = 'res/04B_03__.TTF';
else
$font2 = 'res/pixelmix.ttf';
//Define your weather station model between quotes below
$pws_text = 'PWS MODEL-123';
//Change copyright text if needed or leave as is
$copy_text = '©' . date('Y') . ' atmocom.com';
//Location of weather station.
//Be mindful of text length, available space on
//sticker is limited and text could overflow edges if too long
$pwsloc = 'MYLOCATION, CNTRY';
//Time zone label
$tmzone = 'CET';
//Units used in sticker output
//This should be changed to reflect units of the
//data stored in your SQLite database
$t_unit = '°C';
$wd_unit = '°';
$ws_unit = ' KT';
$p_unit = ' hPa';
$r_unit = ' mm';
$h_unit = '%';
// Gets latest weather data record from SQLite database
$data = dbget_last();
//Include custom drawing code for respective sticker size,
//depending on URL parameter
if($size === 'mini')
include('agfx_mini.php');
else
include('agfx_norm.php');
$imgname = imagecreatefrompng('_badge.png');
header('Content-Type: image/png');
imagepng($imgname);
imagedestroy($imgname);
function calc_wind_arrow($x, $y, $d, $px)
{
$d_rad = deg2rad($d);
//Calculate wind arrow (triangle) top point on wind rose
$x1 = $x + ($px * sin($d_rad));
$y1 = $y - ($px * cos($d_rad));
//Calculate 2x base points, each angled 16 degrees, triangle height = 4 pixels
$d_rad = deg2rad($d-19);
$px-=9;
$x2 = $x + ($px * sin($d_rad));
$y2 = $y - ($px * cos($d_rad));
$d_rad = deg2rad($d+19);
$x3 = $x + ($px * sin($d_rad));
$y3 = $y - ($px * cos($d_rad));
//Return array with points for poly-line draw
return array($x1, $y1, $x2, $y2, $x3, $y3);
}
function dbget_last()
{
global $dbFile;
if(!file_exists($dbFile)) die();
try {
$db = new PDO('sqlite:' . $dbFile);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql_qry = 'SELECT * FROM wxdata WHERE ID >= (SELECT MAX(ID) FROM wxdata)';
$stmt = $db->prepare($sql_qry);
$stmt->execute();
$res = $stmt->fetchAll(PDO::FETCH_ASSOC);
} catch(PDOException $e) {
// Print PDOException message
echo $e->getMessage();
die('DB ERROR: ' . $e->getMessage());
}
$db=null;
return $res;
}
//Define parameters supported by DB table
abstract class Params
{
const STATIONID = 1;
const TEMP = 2;
const DEWPT = 3;
const RHUM = 4;
const BARO = 5;
const WINDDIR = 6;
const WINDVEL = 7;
const WGUSTDIR = 8;
const WGUSTVEL = 9;
const PRECIP = 10;
const PRECIPDAY = 11;
const UVIDX = 12;
const SOLAR = 13;
const INTEMP = 14;
const INRHUM = 15;
const SOILTEMP = 16;
const SOILMOIST = 17;
const LEAFWET = 18;
const WEATHER = 19;
const CLOUDS = 20;
const VISNM = 21;
const RES1 = 22;
const RES2 = 23;
const RES3 = 24;
const RES4 = 25;
const RES5 = 26;
}
?>