Skip to content

Commit

Permalink
added different offline measures, improved GPIO input field, improved…
Browse files Browse the repository at this point in the history
… update mechanism, added delete csv,
  • Loading branch information
JavanXD committed Apr 24, 2019
1 parent cebe588 commit f42663c
Show file tree
Hide file tree
Showing 27 changed files with 365 additions and 84 deletions.
16 changes: 8 additions & 8 deletions backend/_vars.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php
$honeyPiHome = '/home/pi/HoneyPi';
$scriptsFolder = $honeyPiHome . '/rpi-scripts';
$backendFolder = '/var/www/html/backend';
$shellDir = $backendFolder . '/shell-scripts';
$logFile = $scriptsFolder . '/error.log';
$settingsFile = $backendFolder . '/settings.json';
$csvFile = $scriptsFolder + '/offline.csv';
$wittyPiPath = '/home/pi/wittyPi';
$honeyPiHome = "/home/pi/HoneyPi";
$scriptsFolder = $honeyPiHome . "/rpi-scripts";
$backendFolder = "/var/www/html/backend";
$shellDir = $backendFolder . "/shell-scripts";
$logFile = $scriptsFolder . "/error.log";
$settingsFile = $backendFolder . "/settings.json";
$csvFile = $scriptsFolder . "/offline.csv";
$wittyPiPath = "/home/pi/wittyPi";

// function to clear files
function clear_file($file) {
Expand Down
8 changes: 6 additions & 2 deletions backend/check_internet.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@ function is_connected()
// see https://superuser.com/a/769248
$filename = "http://www.msftncsi.com/ncsi.txt";
$check = "Microsoft NCSI";
$content = file_get_contents($filename);
try {
$content = file_get_contents($filename);
} catch (Exception $e) {
$content = $e->getMessage();
}
if($content === $check)
{
return ['connected' => true,
'content' => null];
} else {
$obj = ['connected' => false,
return ['connected' => false,
'content' => $content];
}

Expand Down
3 changes: 2 additions & 1 deletion backend/offlinecsv.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
include_once("_headers.php");
require_once('_vars.php');
require_once("_vars.php");

// csv
header('Content-Type: text/csv; charset=utf-8');
// ie no sniff
Expand Down
4 changes: 2 additions & 2 deletions backend/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
"debug": true,
"wittyPi_enabled": false,
"wittyPi_script": "",
"offline": false,
"offline": 0,
"w1gpio": 11
}
}
56 changes: 44 additions & 12 deletions backend/update.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,42 +15,74 @@
ob_implicit_flush(1); // Implicit flush at each output command

require_once('_vars.php');
// text
header('Content-type:text/plain;charset=utf-8');
// json
header('Content-type:application/json;charset=utf-8');

// function for shell script
function updateGit() {
return shell_exec("sudo git pull --rebase origin master");
return shell_exec("sudo git pull");
}
function update() {
return shell_exec("sudo sh ".$GLOBALS['honeyPiHome']."/update.sh");
}
function install() {
exec("sudo sh ".$GLOBALS['shellDir']."/web-install.sh", $out, $status);
if (0 === $status) {
var_dump($out);
return var_dump($out);
} else {
echo "Command failed with status: $status";
return "Command failed with status: $status";
}
}

function getVersionInfo() {
$obj = new \stdClass();
$context = stream_context_create(
array(
"http" => array(
"header" => "User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36"
)
)
);
try {
$urlScripts = "https://api.github.com/repos/Honey-Pi/rpi-scripts/releases/latest";
$contentScripts = file_get_contents($urlScripts, false, $context);

$urlWebinterface = "https://api.github.com/repos/Honey-Pi/rpi-webinterface/releases/latest";
$contentWebinterface = file_get_contents($urlWebinterface, false, $context);

$obj->scripts = json_decode($contentScripts);
$obj->webinterface = json_decode($contentWebinterface);

return $obj;
} catch (Exception $e) {
$obj->error = 'Exception: '. $e->getMessage(). "\n";
}
return $obj;
}

$output = new \stdClass();
// switch working dir
echo "Changed working dir from ";
echo getcwd() . "\n";
$output->chdir = "Changed working dir from ";
$output->chdir .= getcwd() . "\n";
chdir($GLOBALS['honeyPiHome']);
echo " to " . getcwd() . "\n";
$output->chdir .= " to " . getcwd() . "\n";

if (isset($_GET['mode']))
{
echo "Update " . $GLOBALS['honeyPiHome'] . " git:" . "\n";
echo updateGit();
$output->git = "Update " . $GLOBALS['honeyPiHome'] . " git:" . "\n";
$output->git .= updateGit();

if ($_GET['mode'] === 'update') {
echo update();
$output->mode = update();
} else if ($_GET['mode'] === 'install')
{
install();
$output->mode = install();
} else if ($_GET['mode'] === 'versionInfo')
{
$output->mode = getVersionInfo();
}
}

echo json_encode($output, JSON_PRETTY_PRINT);

?>
16 changes: 12 additions & 4 deletions dist/assets/i18n/translations_de.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
"errorSaving": "<strong>Fehler!</strong> Die Einstellungen konnten nicht gespeichert werden.",
"gpio": "<b>GPIO:</b> Die Kontaktstifte auf dem Raspberry Pi Board haben zwei Nummerierungen. Eine physische von 1 bis 40 und eine für jeden frei programmierbaren GPIO. Bei der Angabe des Kontaktstiftes wird hier im Wartungsmodus immer die GPIO Nummerierung angegeben.",
"hx711": {
"offset": "<b>Offset:</b> Beeinflusst das Messergebnis indem das Offset vom Messwert abgezogen wird.\n<br />Kann auch eine negative Zahl sein. Angabe in Gramm. Standard ist \"0\".",
"scale": "<b>Skalierungswert:</b> Beeinflusst das Messergebnis indem (Messwert-Offset) durch den Skalierungswert geteilt wird.\n<br />Es sind vier Nachkommastellen erlaubt und die Nachkommastellen werden mit Punkt und nicht mit Komma getrennt. Standard ist \"1\"."
"offset": "<b>Offset:</b> Beeinflusst das Messergebnis indem das Offset vom Messwert abgezogen wird.\n<br />Kann auch eine negative Zahl sein. <b>Angabe in Gramm.</b> Standard ist \"0\".",
"scale": "<b>Skalierungswert:</b> Beeinflusst das Messergebnis indem (Messwert-Offset) durch den Skalierungswert geteilt wird.\n<br />Es sind vier Nachkommastellen erlaubt und die <b>Nachkommastellen werden mit Punkt</b> und nicht mit Komma getrennt. Standard ist \"1\"."
},
"noTempSensorFound": "Es konnte kein Temperatursensor am Gerät gefunden werden.",
"notAP": "<strong>Hinweis:</strong> Der Wartungsmodus wird nicht über den \"HoneyPi\"-AccessPoint aufgerufen. Änderungen werden daher erst nach einem Neustart aktiv (da der Tastendruck ausbleibt).",
"saved": "<strong>Gespeichert!</strong> Die Einstellungen wurden gespeichert.",
"updateInfo": "1. Das Systemupdate kann eine ganze Weile dauern. Es ist wichtig, dass ununterbrochen eine Internetverbindung und Stromversorgung besteht.<br>\n2. Der Raspberry sollte über ein LAN Kabel oder mindestens über WLAN verbunden sein. <br>\n3. Im Reiter \"Internetverbindung\" muss der Button \"Teste Internetverbindung\" einen Erfolg vermelden.<br>\n4. Die Einstellungen gehen dabei verloren (Reset). Daher vorher die Einstellungsdatei exportieren.",
"updateAP": "<b>Hinweis:</b> Der Wartungsmodus wird von Dir über den \"HoneyPi\"-AccessPoint aufgerufen. Dies hat zur Folge, dass während des Wartungsmodus keine Internetverbindung über WLAN hergestellt wird. Du kannst im Reiter \"Internetverbindung\" ein WLAN-Netzwerk deiner Wahl eintragen. Bei einem Raspberry 3 kann zum Systemupdate ein LAN Kabel angeschlossen werden. <b>Bitte beachte Schritt 3. Wir empfehlen den Aufruf über die IP/Hostname des Raspberrys im Heimnetzwerk.</b>",
"updateInfo": "1. Das Datenvolumen des Surfsticks kann dabei verbraucht werden. <br>\n2. Es empfiehlt sich daher, den Raspberry Zero für das Systemupdate vom Surfstick zu trennen und ihn mit einem vorhandenen WLAN-Netzwerk zu verbinden.<br>\n3. Anschließend sollte der Wartungsmodus nicht über den \"HoneyPi\"-AccessPoint, sondern über die IP-Adresse des Raspberrys aufgerufen werden. <br>\n4. Die Einstellungen gehen dabei verloren (Reset). Daher vorher die Einstellungsdatei exportieren.",
"updateNotAP": "<b>Erfolgreich verbunden!</b> Du rufst den Raspberry nicht über den \"HoneyPi\"-AccessPoint auf, sondern über die IP-Adresse im Heimnetzwerk. <b>Du kannst Schritt 3 überspringen.</b>",
"wittypi": "Mit Hilfe des zusätzlichen Witty Pi Moduls kann der Raspberry Pi zeitgesteuert werden.\nWir bieten bereits drei nützliche Programme.\nDiese können im Eingabefeld auch verändert werden. Voraussetzung ist das <strong>WittyPi 2 oder Mini</strong>-Modul."
},
"brand": "HoneyPi",
Expand Down Expand Up @@ -70,10 +72,15 @@
"title": "Messdaten"
},
"offline": {
"delete": "Löschen",
"export": "Messdaten herunterladen",
"exportButton": "Herunterladen",
"infoExport": "Die Messdaten werden in einer CSV-Datei abgespeichert. Diese Datei kann anschließend in den ThingSpeak Channel importiert werden. Ansonsten können die Messdaten auch mit der iOS-/Web-App visualisiert werden.",
"offline": "Messdaten offline speichern ohne ThingSpeak",
"radio0": "Online: Ausschließlich Online an ThingSpeak übertragen",
"radio1": "Beides: Zu ThingSpeak übertragen und in CSV-Datei ablegen",
"radio2": "Bei Fehlern: Nur bei Internet-Verbindungsfehlern in CSV-Datei schreiben",
"radio3": "Offline: Ausschließlich Offline in CSV-Datei schreiben",
"title": "Offline Messdaten"
},
"sensors": {
Expand Down Expand Up @@ -119,8 +126,9 @@
"update": {
"export": "Einstellungen",
"install": "System neu installieren",
"preupdate": "Nach neuster Version suchen",
"title": "Systemupdate",
"update": "Update"
"update": "Jetzt aktualisieren"
},
"wittypi": {
"empty": "Leeres Feld",
Expand Down
12 changes: 10 additions & 2 deletions dist/assets/i18n/translations_en.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
"noTempSensorFound": "No temperature sensor could be found on the device.",
"notAP": "<strong>Note:</strong> The maintenance mode is not called through the 'HoneyPi' AccessPoint. Changes are therefore only made after a restart (because the pushbutton is not being pressed).",
"saved": "<strong>Saved!</strong> The settings have been saved.",
"updateInfo": "The system update can take quite a while. It is important that you have an Internet connection and power supply without interruption.\nThe Raspberry should be connected via a LAN cable or at least WiFi. \nThe settings will be lost (completely reset). Therefore export the settings file beforehand.",
"updateAP": "<b>Note:</b> The maintenance mode is called by you via the \"HoneyPi\"-AccessPoint. As a result, no Internet connection is established via WiFi during maintenance mode. You can enter a WLAN network of your choice in the \"Internet connection\" tab. With a Raspberry 3, a LAN cable can be connected for system updates. <b>Please note step 3. We recommend using the IP/Hostname of the Raspberry in the home network.</b>",
"updateInfo": "1. The data volume of the surf stick can be used up. <br>\n2. It is therefore recommended to disconnect the Raspberry Zero from the Surfstick for the system update and connect it to an existing WiFi network.<br>\n3. Afterwards, the maintenance mode should not be called via the \"HoneyPi\" AccessPoint, but via the IP address of the Raspberry. <br>\n4. The settings will be lost (reset). Therefore export the settings file beforehand.",
"updateNotAP": "<b>Successfully connected!</b> You call the Raspberry not via the \"HoneyPi\" AccessPoint, but via the IP address in the home network. <b>You can skip step 3.</b>",
"wittypi": "With the help of the additional Witty Pi module, the Raspberry Pi can be time-controlled.\nWe already offer three useful programs.\nThese can also be changed in the input field. Prerequisite is the <strong>Witty Pi Mini</strong> module."
},
"brand": "HoneyPi (en)",
Expand Down Expand Up @@ -70,10 +72,15 @@
"title": "Measurement data"
},
"offline": {
"delete": "Delete",
"export": "Download measurement data",
"exportButton": "Download",
"infoExport": "The measurement data is stored in a CSV file. This file can then be imported into the ThingSpeak Channel. Otherwise, the measurement data can also be visualized with the iOS/Web app.",
"offline": "Offline Measurement without ThingSpeak",
"radio0": "Online: Transfer exclusively online to ThingSpeak",
"radio1": "Both: Transfer to ThingSpeak and save to CSV file",
"radio2": "Errors: Write to CSV file only for Internet connection errors",
"radio3": "Offline: Write only offline to CSV file",
"title": "Offline Measurement data"
},
"sensors": {
Expand Down Expand Up @@ -119,8 +126,9 @@
"update": {
"export": "Settings",
"install": "Reinstall system",
"preupdate": "Check for new version",
"title": "System update",
"update": "Update"
"update": "Update now"
},
"wittypi": {
"empty": "Empty field",
Expand Down
2 changes: 1 addition & 1 deletion dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@
<script type="text/javascript" src="assets/jquery-3.3.1.min.js"></script>
<script type="text/javascript" src="assets/popper.min.js"></script>
<script type="text/javascript" src="assets/bootstrap-4.1.1/js/bootstrap.min.js"></script>
<script type="text/javascript" src="runtime.26209474bfa8dc87a77c.js"></script><script type="text/javascript" src="polyfills.2f67a12a18dc8be50759.js"></script><script type="text/javascript" src="main.542df1aa9ec4dcbc47d4.js"></script></body>
<script type="text/javascript" src="runtime.26209474bfa8dc87a77c.js"></script><script type="text/javascript" src="polyfills.2f67a12a18dc8be50759.js"></script><script type="text/javascript" src="main.c58956e55352131dc440.js"></script></body>
</html>
1 change: 0 additions & 1 deletion dist/main.542df1aa9ec4dcbc47d4.js

This file was deleted.

1 change: 1 addition & 0 deletions dist/main.c58956e55352131dc440.js

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { ThingspeakComponent } from './components/thingspeak/thingspeak.componen
import { WittypiComponent } from './components/wittypi/wittypi.component';
import { UpdateComponent } from './components/update/update.component';
import { OfflineComponent } from './components/offline/offline.component';
import { GpioFieldComponent } from './components/settings/gpio-field/gpio-field.component';

export function createTranslateLoader(http: HttpClient) {
return new TranslateHttpLoader(http, './assets/i18n/translations_', '.json');
Expand All @@ -44,7 +45,8 @@ const appRoutes: Routes = [
ThingspeakComponent,
WittypiComponent,
UpdateComponent,
OfflineComponent
OfflineComponent,
GpioFieldComponent
],
imports: [
BrowserModule,
Expand Down
4 changes: 4 additions & 0 deletions src/app/components/measurement/measurement.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
</div>
</div>
</ng-container>
<!--
<p [translate]="'settings.measurement.construction'"></p>
-->
<br>
<button class="btn btn-primary btn-sm" type="button" role="button"
(click)="getMeasurement()" [disabled]="isLoading" [translate]="'settings.measurement.get'"></button>

33 changes: 27 additions & 6 deletions src/app/components/offline/offline.component.html
Original file line number Diff line number Diff line change
@@ -1,17 +1,38 @@
<div class="row">
<div class="col-12">
<div class="alert alert-info" role="alert">
<a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
<span [innerHTML]="'settings.offline.infoExport' | translate"></span>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="offline" id="offline0" [value]="0" [(ngModel)]="settings.offline" [checked]="settings.offline==0 || settings.offline==undefined">
<label class="form-check-label" for="offline0" [translate]="'settings.offline.radio0'"></label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="offline" id="offline1" [value]="1" [(ngModel)]="settings.offline" [checked]="settings.offline==1">
<label class="form-check-label" for="offline1" [translate]="'settings.offline.radio1'"></label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="offline" id="offline2" [value]="2" [(ngModel)]="settings.offline" [checked]="settings.offline==2">
<label class="form-check-label" for="offline2" [translate]="'settings.offline.radio2'"></label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="offline" id="offline3" [value]="3" [(ngModel)]="settings.offline" [checked]="settings.offline==3">
<label class="form-check-label" for="offline3" [translate]="'settings.offline.radio3'"></label>
</div>
<!--Alt:
<div class="form-group form-check">
<input type="checkbox" class="form-check-input" name="offline" [(ngModel)]="settings.offline" id="offline">
<label class="form-check-label" for="offline" [innerHTML]="'settings.offline.offline' | translate"></label>
</div>
-->
</div>
</div>
<div class="alert alert-info" role="alert">
<a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
<span [innerHTML]="'settings.offline.infoExport' | translate"></span>
</div>
<hr />
<h5 class="h5" [translate]="'settings.offline.export'"></h5>
<a href="{{apiURL}}offlinecsv.php" target="_blank" download="HoneyPi-export.csv" class="btn btn-primary btn-sm"
[translate]="'settings.offline.exportButton'"></a>
<div class="btn-group btn-group-sm" role="group">
<a href="{{apiURL}}offlinecsv.php" target="_blank" download="HoneyPi-export.csv" class="btn btn-primary btn-sm"
[translate]="'settings.offline.exportButton'"></a>
<button class="btn btn-danger btn-sm" type="button" role="button" (click)="deleteCsv()" [translate]="'settings.offline.delete'"></button>
</div>

9 changes: 8 additions & 1 deletion src/app/components/offline/offline.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core';
import {Settings} from '../../models/settings.model';
import {environment} from '../../../environments/environment';
import {AppService} from '../../services/app.service';


@Component({
Expand All @@ -23,12 +24,18 @@ export class OfflineComponent implements OnInit {
@Output()
settingsChange: EventEmitter<Settings> = new EventEmitter<Settings>();

constructor() { }
constructor(private appService: AppService) { }

public apiURL;

ngOnInit() {
this.apiURL = environment.apiURL;
}

deleteCsv(): void {
this.appService.deleteCsv()
.subscribe(res => {
}, (err: any) => {console.error(err); });
}

}
Loading

0 comments on commit f42663c

Please sign in to comment.