provider for pinging sensebox

development
Thiemann96 5 years ago
parent f5b06f3fe4
commit ce3216c159

@ -38,6 +38,11 @@
<!-- OTA Mode guide-->
<ion-slide>
<ion-grid>
<ion-row align-items-center>
<ion-col col-12>
<h2 translate>OTAWIZ.OTAMODE.TITLE</h2>
</ion-col>
</ion-row>
<ion-row align-items-center>
<ion-col col-12 col-md-6>
<ion-card (click)="showAutomatic()">
@ -70,7 +75,6 @@
<ion-grid>
<ion-row align-items-center>
<ion-col col-12 col-md-6>
<h2 translate>OTAWIZ.OTAMODE.TITLE</h2>
<img class="tutorial_gif" src="../../assets/imgs/ota_modus.gif" />
<p [innerHTML]="'OTAWIZ.OTAMODE.TEXT' | translate"></p>
</ion-col>
@ -81,7 +85,7 @@
<li [innerHTML]="'OTAWIZ.OTAMODE.STEP3' | translate"></li>
</ol>
<!-- @TODO: diagram! -->
<button ion-button large clear icon-end color="primary" (click)="slides.slideNext()">
<button ion-button large clear icon-end color="primary" (click)="slides.slideNext()">
{{ 'OTAWIZ.BTN_NEXT' | translate }}
<ion-icon name="arrow-forward"></ion-icon>
</button>
@ -93,21 +97,26 @@
<ion-slide *ngIf="automatic" id="automatic-slide">
<ion-grid>
<ion-row align-items-center>
<ion-col col-12 col-md-6>
<h2 translate>OTAWIZ.OTAMODE.TITLE</h2>
<p [innerHTML]="'OTAWIZ.OTAMODE.TEXT' | translate"></p>
</ion-col>
<ion-col col-12 col-md-6>
<ol style="text-align: left">
<li [innerHTML]="'OTAWIZ.OTAMODE.STEP1' | translate"></li>
<li [innerHTML]="'OTAWIZ.OTAMODE.STEP2' | translate"></li>
<li [innerHTML]="'OTAWIZ.OTAMODE.STEP3' | translate"></li>
<li [innerHTML]="'OTAWIZ.OTAMODE.AUTOMATIC.STEP1' | translate"></li>
<li [innerHTML]="'OTAWIZ.OTAMODE.AUTOMATIC.STEP2' | translate"></li>
<li [innerHTML]="'OTAWIZ.OTAMODE.AUTOMATIC.STEP3' | translate"></li>
</ol>
</ion-col>
<ion-col col-12 col-md-6>
<!-- @TODO: diagram! -->
<button ion-button large clear icon-end color="primary" (click)="slides.slideNext()">
<button *ngIf="requestSuccessful;else request" ion-button large clear icon-end color="primary" (click)="slides.slideNext()">
{{ 'OTAWIZ.BTN_NEXT' | translate }}
<ion-icon name="arrow-forward"></ion-icon>
</button>
<ng-template #request>
<button ion-button large clear icon-end color="primary" (click)="makeRequest()">
{{ 'OTAWIZ.BTN_REQUEST' | translate }}
<ion-icon name="arrow-forward"></ion-icon>
</button>
</ng-template>
</ion-col>
</ion-row>
</ion-grid>

@ -50,6 +50,7 @@ export class OtaWizardPage implements OnInit, OnDestroy {
private counts = { compile: 0, connect: 0, upload: 0 }
private manual = false;
private automatic = false;
private requestSuccessful = false;
constructor(
private network: Network,
private otaWifi: OtaWifiProvider,
@ -141,7 +142,16 @@ export class OtaWizardPage implements OnInit, OnDestroy {
}
activateOta(){
async makeRequest(){
try{
// open modal that shows loading
await this.otaWifi.activateOtaMode();
this.requestSuccessful = true;
}
catch(err){
console.log(err)
}
// Sends request; upon successful response go to next slide (wifi selection)
}

@ -9,7 +9,7 @@ declare var WifiWizard2: any
// corresponding to the initial MCU firmware
const SSID_PREFIX = 'sensebox'
const SENSEBOX_API = 'http://192.168.1.1'
const URL_sensebox = 'http://192.168.0.46'
/*
Interface for uploading a binary to a senseBox MCU.
*/
@ -79,6 +79,17 @@ export class OtaWifiProvider {
.toPromise()
}
async activateOtaMode():Promise<any>{
return this.http.get(URL_sensebox)
.pipe(timeout(5000),catchError(err=>{
throw new Error('senseBox not found. Is it running the proper OpenSenseMap Sketch?')
}))
.toPromise()
.then((response:any)=>{
return response;
})
}
}
export enum WifiStrategy {

Loading…
Cancel
Save