-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLoRa.php
56 lines (45 loc) · 1.68 KB
/
LoRa.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
<?php
error_reporting(E_ALL);
ini_set ('display_errors', 'On');
include ("login/config.php");
$var1 = file_get_contents('php://input');
//$var = json_decode($json);
$var2 = json_decode($var1);
//echo $var1;
$var3 = "Payload: ";
$var3 .= base64_decode($var2->payload_raw);
$payload2 = base64_decode($var2->payload_raw);
$var3 .= "<br /> Time: ";
$var3 .= $var2->metadata->time;
$var3 .= "<br /> Frequenz: ";
$var3 .= $var2->metadata->frequency;
$var3 .= "<br /> Gateway_id: ";
$var3 .= $var2->metadata->gateways[0]->gtw_id;
$var3 .= "<br /> Channel: ";
$var3 .= $var2->metadata->gateways[0]->channel;
$var3 .= "<br /> RSSI: ";
$var3 .= $var2->metadata->gateways[0]->rssi;
$var3 .= "<br /> SNR: ";
$var3 .= $var2->metadata->gateways[0]->snr;
$time = time();
$frequency = $var2->metadata->frequency;
$gwid = $var2->metadata->gateways[0]->gtw_id;
$channel = $var2->metadata->gateways[0]->channel;
$rssi = $var2->metadata->gateways[0]->rssi;
$SNR = $var2->metadata->gateways[0]->snr;
$payload = base64_decode($var2->payload_raw);
$data = explode("a", $payload);
$spannung = round(($data[0] * 17)/1000, 3);
$strom = round((($data[1] * 58.59375)-30000)*-1);
system('echo "'.$spannung.'" > /var/www/th/V');
system('echo "'.$strom.'" > /var/www/th/A');
$timestamp = time();
$eintrag = "INSERT INTO LoRaSolar (time, frequency, gtw_id, channel, rssi, snr, payload, spannung, strom) VALUES ('$timestamp', '$frequency', '$gwid', '$channel', '$rssi', '$SNR', '$payload', '$spannung', '$strom');";
$eintragen = mysqli_query($db, $eintrag);
$var3 .= mysql_error();
//$var1 = $var->payload_raw;
$handle = fopen ("loradata.html", "w");
fwrite ($handle, "$spannung ; $strom");
fwrite ($handle, $var3);
fclose ($handle);
?>