mirror of
https://github.com/sensebox/blockly-app
synced 2025-06-08 10:05:50 +02:00
changed ota app according to new osem sketch
This commit is contained in:
parent
5801e7a4d5
commit
0e3f43e2ec
3 changed files with 13 additions and 51 deletions
|
@ -103,16 +103,10 @@
|
||||||
</ion-col>
|
</ion-col>
|
||||||
<ion-col col-12 col-md-6>
|
<ion-col col-12 col-md-6>
|
||||||
<!-- @TODO: diagram! -->
|
<!-- @TODO: diagram! -->
|
||||||
<button *ngIf="requestSuccessful;else request" 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 }}
|
{{ 'OTAWIZ.BTN_NEXT' | translate }}
|
||||||
<ion-icon name="arrow-forward"></ion-icon>
|
<ion-icon name="arrow-forward"></ion-icon>
|
||||||
</button>
|
</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-col>
|
||||||
</ion-row>
|
</ion-row>
|
||||||
</ion-grid>
|
</ion-grid>
|
||||||
|
@ -142,7 +136,7 @@
|
||||||
</ng-container>
|
</ng-container>
|
||||||
</ion-slide>
|
</ion-slide>
|
||||||
<!-- wifi selection -->
|
<!-- wifi selection -->
|
||||||
<ion-slide id="wifi-slide">
|
<ion-slide id="wifi-slide" *ngIf="!slideIsHidden(slideWifi)">
|
||||||
<ion-grid>
|
<ion-grid>
|
||||||
<div id="wifi-manual" *ngIf="state.wifiSelection == 'manual'">
|
<div id="wifi-manual" *ngIf="state.wifiSelection == 'manual'">
|
||||||
<ion-row align-items-center>
|
<ion-row align-items-center>
|
||||||
|
|
|
@ -20,6 +20,7 @@ import { OtaWifiProvider, WifiStrategy } from '../../providers/ota-wifi/ota-wifi
|
||||||
import { CompilerProvider } from '../../providers/compiler/compiler';
|
import { CompilerProvider } from '../../providers/compiler/compiler';
|
||||||
import { LoggingProvider } from '../../providers/logging/logging';
|
import { LoggingProvider } from '../../providers/logging/logging';
|
||||||
import {ErrorPage} from '../../pages/error/error'
|
import {ErrorPage} from '../../pages/error/error'
|
||||||
|
import { isUndefined } from 'ionic-angular/umd/util/util';
|
||||||
@IonicPage()
|
@IonicPage()
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'page-ota-wizard',
|
selector: 'page-ota-wizard',
|
||||||
|
@ -52,7 +53,7 @@ export class OtaWizardPage implements OnInit, OnDestroy {
|
||||||
private counts = { compile: 0, connect: 0, upload: 0 }
|
private counts = { compile: 0, connect: 0, upload: 0 }
|
||||||
private manual = false;
|
private manual = false;
|
||||||
private automatic = false;
|
private automatic = false;
|
||||||
private requestSuccessful = false;
|
private wifiSlideHidden = false;
|
||||||
constructor(
|
constructor(
|
||||||
private network: Network,
|
private network: Network,
|
||||||
private otaWifi: OtaWifiProvider,
|
private otaWifi: OtaWifiProvider,
|
||||||
|
@ -134,16 +135,18 @@ export class OtaWizardPage implements OnInit, OnDestroy {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
showAutomatic() {
|
showAutomatic() {
|
||||||
|
this.slides.lockSwipeToNext(false);
|
||||||
|
this.wifiSlideHidden = true;
|
||||||
this.automatic = true;
|
this.automatic = true;
|
||||||
this.manual = false;
|
this.manual = false;
|
||||||
this.slides.lockSwipeToNext(false);
|
|
||||||
this.slides.slideNext()
|
this.slides.slideNext()
|
||||||
}
|
}
|
||||||
|
|
||||||
showManual() {
|
showManual() {
|
||||||
|
this.slides.lockSwipeToNext(false);
|
||||||
|
this.wifiSlideHidden = false;
|
||||||
this.manual = true;
|
this.manual = true;
|
||||||
this.automatic = false;
|
this.automatic = false;
|
||||||
this.slides.lockSwipeToNext(false);
|
|
||||||
this.slides.slideNext()
|
this.slides.slideNext()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -153,32 +156,10 @@ export class OtaWizardPage implements OnInit, OnDestroy {
|
||||||
let modal = this.modalCtrl.create(ErrorPage,message);
|
let modal = this.modalCtrl.create(ErrorPage,message);
|
||||||
|
|
||||||
modal.onDidDismiss(()=>{
|
modal.onDidDismiss(()=>{
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
modal.present();
|
modal.present();
|
||||||
}
|
}
|
||||||
|
|
||||||
async makeRequest() {
|
|
||||||
const loading = await this.loadingController.create({
|
|
||||||
content: 'Pinging senseBox...'
|
|
||||||
});
|
|
||||||
try {
|
|
||||||
// open modal that shows loading
|
|
||||||
|
|
||||||
loading.present();
|
|
||||||
await this.otaWifi.activateOtaMode();
|
|
||||||
this.requestSuccessful = true;
|
|
||||||
}
|
|
||||||
catch (err) {
|
|
||||||
this.slides.lockSwipeToNext(true);
|
|
||||||
this.showModal(err);
|
|
||||||
console.log(err)
|
|
||||||
}
|
|
||||||
loading.dismiss();
|
|
||||||
// Sends request; upon successful response go to next slide (wifi selection)
|
|
||||||
|
|
||||||
}
|
|
||||||
// call logic for each slide
|
// call logic for each slide
|
||||||
onSlideChange() {
|
onSlideChange() {
|
||||||
this.slideHistory.push(OtaSlides[this.currentSlide])
|
this.slideHistory.push(OtaSlides[this.currentSlide])
|
||||||
|
@ -187,20 +168,16 @@ export class OtaWizardPage implements OnInit, OnDestroy {
|
||||||
case OtaSlides.Intro:
|
case OtaSlides.Intro:
|
||||||
this.slides.lockSwipeToNext(false);
|
this.slides.lockSwipeToNext(false);
|
||||||
case OtaSlides.Intro2:
|
case OtaSlides.Intro2:
|
||||||
|
this.slides.lockSwipeToNext(true);
|
||||||
break
|
break
|
||||||
case OtaSlides.Intro3:
|
case OtaSlides.Intro3:
|
||||||
if(this.automatic){
|
|
||||||
this.slides.lockSwipeToNext(true);
|
|
||||||
}
|
|
||||||
if(this.manual){
|
|
||||||
this.slides.lockSwipeToNext(false);
|
|
||||||
}
|
|
||||||
break
|
break
|
||||||
case OtaSlides.Compilation:
|
case OtaSlides.Compilation:
|
||||||
this.handleCompilation()
|
this.handleCompilation()
|
||||||
break
|
break
|
||||||
|
|
||||||
case OtaSlides.WifiSelection:
|
case OtaSlides.WifiSelection:
|
||||||
|
if(this.automatic) this.slides.slideNext()
|
||||||
this.handleWifiSelection()
|
this.handleWifiSelection()
|
||||||
break
|
break
|
||||||
|
|
||||||
|
@ -290,6 +267,7 @@ export class OtaWizardPage implements OnInit, OnDestroy {
|
||||||
this.counts.upload++
|
this.counts.upload++
|
||||||
this.state.upload = 'uploading'
|
this.state.upload = 'uploading'
|
||||||
try {
|
try {
|
||||||
|
|
||||||
const res = await this.otaWifi.uploadFirmware(this.compiledSketch)
|
const res = await this.otaWifi.uploadFirmware(this.compiledSketch)
|
||||||
this.log.debug(JSON.stringify(res, null, 2))
|
this.log.debug(JSON.stringify(res, null, 2))
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ declare var WifiWizard2: any
|
||||||
// corresponding to the initial MCU firmware
|
// corresponding to the initial MCU firmware
|
||||||
const SSID_PREFIX = 'sensebox'
|
const SSID_PREFIX = 'sensebox'
|
||||||
const SENSEBOX_API = 'http://192.168.1.1'
|
const SENSEBOX_API = 'http://192.168.1.1'
|
||||||
const URL_sensebox = 'http://192.168.0.46'
|
const URL_sensebox = 'http://10.0.1.12'
|
||||||
/*
|
/*
|
||||||
Interface for uploading a binary to a senseBox MCU.
|
Interface for uploading a binary to a senseBox MCU.
|
||||||
*/
|
*/
|
||||||
|
@ -70,7 +70,7 @@ export class OtaWifiProvider {
|
||||||
|
|
||||||
async uploadFirmware (binary: ArrayBuffer): Promise<any> {
|
async uploadFirmware (binary: ArrayBuffer): Promise<any> {
|
||||||
// TODO: send checksum?
|
// TODO: send checksum?
|
||||||
return this.http.post(`${SENSEBOX_API}/sketch`, binary, {
|
return this.http.post(`${URL_sensebox}/sketch`, binary, {
|
||||||
responseType: 'text',
|
responseType: 'text',
|
||||||
})
|
})
|
||||||
.pipe(timeout(5000), catchError(err => {
|
.pipe(timeout(5000), catchError(err => {
|
||||||
|
@ -79,16 +79,6 @@ export class OtaWifiProvider {
|
||||||
.toPromise()
|
.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;
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue