fix integration with MCU OTA firmware

ios
Norwin 6 years ago
parent 28b30b37e3
commit 3faea789cb

@ -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"
},

@ -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, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/\n/g, '<br/>')
}
}
}

@ -1,7 +1,9 @@
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<any> {
async callcompiler(sketch : string): Promise<ArrayBuffer> {
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()
.then((response: any) => {
const url = `${URL}/download?id=${response.data.id}&board=sensebox-mcu`
return this.http.get(url, { responseType: 'arraybuffer' }).toPromise()
});
};
}

@ -62,12 +62,12 @@ export class OtaWifiProvider {
: WifiWizard2.connect(ssid, true)
}
async uploadFirmware (binary: string): Promise<any> {
async uploadFirmware (binary: ArrayBuffer): Promise<any> {
// 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()

Loading…
Cancel
Save