diff --git a/package.json b/package.json index a34738e..8772eee 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,8 @@ "start": "ionic-app-scripts serve", "clean": "ionic-app-scripts clean", "build": "ionic-app-scripts build", - "android:deploy": "ionic cordova build android; adb install -r platforms/android/app/build/outputs/apk/debug/app-debug.apk", + "android:build": "ionic cordova build android", + "android:deploy": "adb install -r platforms/android/app/build/outputs/apk/debug/app-debug.apk", "android:start": "adb shell am force-stop io.ionic.starter; adb shell am start -n io.ionic.starter/io.ionic.starter.MainActivity; sleep 1; adb logcat | grep -F \"`adb shell ps | grep io.ionic.starter | cut -c15-18`\"", "lint": "ionic-app-scripts lint" }, diff --git a/src/pages/ota-wizard/ota-wizard.ts b/src/pages/ota-wizard/ota-wizard.ts index a3209a0..6f1e361 100644 --- a/src/pages/ota-wizard/ota-wizard.ts +++ b/src/pages/ota-wizard/ota-wizard.ts @@ -29,7 +29,7 @@ export class OtaWizardPage implements OnInit, OnDestroy { sketch = '' filterSsids = true availableSenseboxes: string[] = [] // list of SSIDs - compiledSketch = undefined + compiledSketch: ArrayBuffer = undefined errorMsg = '' state: OtaState = { @@ -127,10 +127,13 @@ export class OtaWizardPage implements OnInit, OnDestroy { } private handleCompilation () { + // skip compilation slide if already compiled this.slides.lockSwipeToNext(!this.compiledSketch) + if (this.compiledSketch) + return this.slides.slideNext(0) // need to go online for compilation. compilation is retriggered via this.onlineSub - if (!this.compiledSketch && !this.state.isOnline) { + if (!this.state.isOnline) { switch (this.otaWifi.strategy) { case WifiStrategy.Automatic: // TODO: auto connect to previous network, if available @@ -138,6 +141,8 @@ export class OtaWizardPage implements OnInit, OnDestroy { this.state.compilation = 'go-online' break } + } else { + this.compileSketch() } } @@ -182,7 +187,12 @@ export class OtaWizardPage implements OnInit, OnDestroy { this.slides.lockSwipeToNext(false) } catch (err) { this.state.compilation = 'error' - this.errorMsg = err.message + this.errorMsg = !err.message ? err : err.message + .replace(/&/g, '&') + .replace(//g, '>') + .replace(/"/g, '"') + .replace(/\n/g, '
') } } } diff --git a/src/providers/compiler/compiler.ts b/src/providers/compiler/compiler.ts index ab009bb..9ea9d66 100644 --- a/src/providers/compiler/compiler.ts +++ b/src/providers/compiler/compiler.ts @@ -1,7 +1,9 @@ -import { HttpClient,HttpHeaders } from '@angular/common/http'; +import { HttpClient, HttpHeaders } from '@angular/common/http'; import { Injectable } from '@angular/core'; +import { timeout } from 'rxjs/operators' -const URL = "https://compiler.sensebox.de" +// const URL = "https://compiler.sensebox.de" +const URL = "http://compiler.snsbx.nroo.de" @Injectable() export class CompilerProvider { @@ -10,23 +12,28 @@ export class CompilerProvider { console.log('Hello CompilerProvider Provider'); } - async callcompiler(sketch : string): Promise { + async callcompiler(sketch : string): Promise { const headers = new HttpHeaders({'Content-Type': 'application/json'} ); const data = { board: 'sensebox-mcu', sketch } // send compilation request, returning a job ID - return this.http.post(`${URL}/compile`, data, { headers }).toPromise() + return this.http.post(`${URL}/compile`, data, { headers }) + .pipe(timeout(4000)) + .toPromise() .catch(err => { - let msg = '' - try { msg = JSON.parse(err.error.message).process } catch (err) {} - throw new Error(msg || err) + let msg = 'unable to contact web compiler. are you online?' + try { + // attempt to extract the compilation error message and clean it up + msg = JSON.parse(err.error.message).process + msg = `compilation error: ${msg.substr(msg.indexOf(' ') + 14)}` + msg = msg.substr(0, msg.indexOf('^')) + } catch (err) {} + throw Error(msg) }) - .then((response:any) =>{ - // download the resulting sketch binary - return this.http.get(`${URL}/download?id=${response.data.id}&board=sensebox-mcu`, { - responseType: 'text', - }).toPromise() - + // download the resulting sketch binary + .then((response: any) => { + const url = `${URL}/download?id=${response.data.id}&board=sensebox-mcu` + return this.http.get(url, { responseType: 'arraybuffer' }).toPromise() }); }; } diff --git a/src/providers/ota-wifi/ota-wifi.ts b/src/providers/ota-wifi/ota-wifi.ts index 21dbbdb..3559d57 100644 --- a/src/providers/ota-wifi/ota-wifi.ts +++ b/src/providers/ota-wifi/ota-wifi.ts @@ -62,12 +62,12 @@ export class OtaWifiProvider { : WifiWizard2.connect(ssid, true) } - async uploadFirmware (binary: string): Promise { + async uploadFirmware (binary: ArrayBuffer): Promise { // TODO: send checksum? - return this.http.post(`${SENSEBOX_API}/flash`, binary, { + return this.http.post(`${SENSEBOX_API}/sketch`, binary, { responseType: 'text', }) - .pipe(timeout(2500), catchError(err => { + .pipe(timeout(5000), catchError(err => { throw new Error('senseBox not found. Is it running in OTA mode?') })) .toPromise()