1
0
Fork 0
mirror of https://github.com/sensebox/blockly-app synced 2025-06-08 10:05:50 +02:00

collect debug information & log it OtaWizardPage

This commit is contained in:
Norwin 2019-02-18 13:21:15 +01:00
parent 8010bd0a0c
commit 48da9819f7
2 changed files with 29 additions and 4 deletions

View file

@ -5,6 +5,7 @@ import { Network } from '@ionic-native/network';
import { OtaWifiProvider } from '../../providers/ota-wifi/ota-wifi'; import { OtaWifiProvider } from '../../providers/ota-wifi/ota-wifi';
import { CompilerProvider } from '../../providers/compiler/compiler'; import { CompilerProvider } from '../../providers/compiler/compiler';
import { TranslateModule } from '@ngx-translate/core'; import { TranslateModule } from '@ngx-translate/core';
import { LoggingProvider } from '../../providers/logging/logging';
@NgModule({ @NgModule({
declarations: [ declarations: [
@ -17,7 +18,8 @@ import { TranslateModule } from '@ngx-translate/core';
providers: [ providers: [
Network, Network,
OtaWifiProvider, OtaWifiProvider,
CompilerProvider CompilerProvider,
LoggingProvider,
] ]
}) })
export class OtaWizardPageModule {} export class OtaWizardPageModule {}

View file

@ -16,6 +16,7 @@ import { Subscription } from 'rxjs/Subscription';
import { OtaWifiProvider, WifiStrategy } from '../../providers/ota-wifi/ota-wifi'; 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';
@IonicPage() @IonicPage()
@Component({ @Component({
@ -44,12 +45,17 @@ export class OtaWizardPage implements OnInit, OnDestroy {
private compiledSketch: ArrayBuffer = undefined private compiledSketch: ArrayBuffer = undefined
private hiddenSlides: OtaSlides[] = [] private hiddenSlides: OtaSlides[] = []
private log: LoggingProvider
private slideHistory: string[] = [OtaSlides[OtaSlides.Intro]] // for debug info in logs
private counts = { compile: 0, connect: 0, upload: 0 }
constructor( constructor(
private network: Network, private network: Network,
private otaWifi: OtaWifiProvider, private otaWifi: OtaWifiProvider,
private navCtrl: NavController, private navCtrl: NavController,
private webcompiler: CompilerProvider, private webcompiler: CompilerProvider,
private changedetect: ChangeDetectorRef, private changedetect: ChangeDetectorRef,
logger: LoggingProvider,
navParams : NavParams, navParams : NavParams,
) { ) {
// for OTA to work, the new sketch has to include the OTA logic as well. // for OTA to work, the new sketch has to include the OTA logic as well.
@ -63,6 +69,14 @@ export class OtaWizardPage implements OnInit, OnDestroy {
sketch = 'void setup() {}\nvoid loop() {}\n' sketch = 'void setup() {}\nvoid loop() {}\n'
this.sketch += sketch this.sketch += sketch
this.log = logger.createChild('OtaWizardPage', {
otaState: this.state,
slideHistory: this.slideHistory,
counts: this.counts,
sketch: this.sketch,
wifis: this.availableSenseboxes,
})
} }
ngOnInit() { ngOnInit() {
@ -88,6 +102,8 @@ export class OtaWizardPage implements OnInit, OnDestroy {
this.offlineSub = this.network.onDisconnect().subscribe(() => { this.offlineSub = this.network.onDisconnect().subscribe(() => {
this.state.isOnline = false this.state.isOnline = false
}) })
this.log.debug('initialized')
} }
ngOnDestroy () { ngOnDestroy () {
@ -105,6 +121,7 @@ export class OtaWizardPage implements OnInit, OnDestroy {
// call logic for each slide // call logic for each slide
onSlideChange () { onSlideChange () {
this.slideHistory.push(OtaSlides[this.currentSlide])
switch (this.currentSlide) { switch (this.currentSlide) {
case OtaSlides.Intro: case OtaSlides.Intro:
case OtaSlides.Intro2: case OtaSlides.Intro2:
@ -124,7 +141,7 @@ export class OtaWizardPage implements OnInit, OnDestroy {
break break
default: default:
console.warn('unknown slide, please define its logic') this.log.warn('unknown slide, please define its logic', { slide: this.currentSlide })
} }
} }
@ -146,6 +163,7 @@ export class OtaWizardPage implements OnInit, OnDestroy {
} }
async connectToSensebox (ssid: string) { async connectToSensebox (ssid: string) {
this.counts.connect++
this.state.wifiSelection = 'connecting' this.state.wifiSelection = 'connecting'
try { try {
await this.otaWifi.connectToSensebox(ssid) await this.otaWifi.connectToSensebox(ssid)
@ -155,6 +173,7 @@ export class OtaWizardPage implements OnInit, OnDestroy {
} catch (err) { } catch (err) {
this.state.wifiSelection = 'error' this.state.wifiSelection = 'error'
this.errorMsg = err.message this.errorMsg = err.message
this.log.error('could not connect to wifi:', err.message)
} }
} }
@ -194,26 +213,29 @@ export class OtaWizardPage implements OnInit, OnDestroy {
this.errorMsg = err.message this.errorMsg = err.message
this.state.wifiSelection = 'error' this.state.wifiSelection = 'error'
this.changedetect.detectChanges() this.changedetect.detectChanges()
this.log.error('could not scan wifi:', err.message)
} }
} }
} }
private async handleUpload () { private async handleUpload () {
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)
console.log(JSON.stringify(res, null, 2)) this.log.debug(JSON.stringify(res, null, 2))
this.state.upload = 'done' this.state.upload = 'done'
this.slides.lockSwipeToNext(false) this.slides.lockSwipeToNext(false)
} catch (err) { } catch (err) {
this.state.upload = 'error' this.state.upload = 'error'
this.errorMsg = err.message this.errorMsg = err.message
this.log.error('could not upload sketch:', err.message)
} }
} }
private async compileSketch () { private async compileSketch () {
this.counts.compile++
this.state.compilation = 'compiling' this.state.compilation = 'compiling'
try { try {
this.compiledSketch = await this.webcompiler.compile(this.sketch) this.compiledSketch = await this.webcompiler.compile(this.sketch)
@ -227,6 +249,7 @@ export class OtaWizardPage implements OnInit, OnDestroy {
.replace(/>/g, '>') .replace(/>/g, '>')
.replace(/"/g, '"') .replace(/"/g, '"')
.replace(/\n/g, '<br/>') .replace(/\n/g, '<br/>')
this.log.error('could not compile sketch:', err.message)
} }
} }
} }