diff --git a/package.json b/package.json index 45d21ec..638d583 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "version": "0.0.0", "scripts": { "ng": "ng", - "start": "ng serve", + "start": "ng serve --proxy-config proxy.conf.json", "build": "ng build", "watch": "ng build --watch --configuration development", "test": "ng test" diff --git a/proxy.conf.json b/proxy.conf.json new file mode 100644 index 0000000..7842dd7 --- /dev/null +++ b/proxy.conf.json @@ -0,0 +1,9 @@ +{ + "/api/*": + { + "target": "https://iot-flasher.thingpulse.com/", + "secure": false, + "logLevel": "debug", + "changeOrigin": true + } +} \ No newline at end of file diff --git a/src/app/app.component.html b/src/app/app.component.html index 3a7cf23..8b941d9 100644 --- a/src/app/app.component.html +++ b/src/app/app.component.html @@ -11,5 +11,5 @@ \ No newline at end of file diff --git a/src/app/components/testrunner/testrunner.component.ts b/src/app/components/testrunner/testrunner.component.ts index 8cd24bc..ebffa0a 100644 --- a/src/app/components/testrunner/testrunner.component.ts +++ b/src/app/components/testrunner/testrunner.component.ts @@ -7,6 +7,8 @@ import { DeviceConfiguration } from 'src/app/model/device-configuration'; import { DeviceConfigurationService } from 'src/app/shared/device-configuration.service'; import { EspPortService } from 'src/app/shared/esp-port.service'; import { Partition, PartitionProgress, sleep, TestState } from 'src/app/shared/utils.service'; +import { TestResultService } from 'src/app/shared/test-result.service'; +import { TestResult } from 'src/app/model/test-result'; @Component({ selector: 'app-testrunner', @@ -17,8 +19,8 @@ export class TestrunnerComponent implements OnInit { deviceId: string; title = 'ThingPulse Hardware Test Tool'; - firmwareMessages: any = []; - displayedColumns: string[] = ['heapSize', 'freeHeap', 'psramSize', 'freePsram']; + firmwareMessages: FirmwareMessage[] = []; + @ViewChild('stepper') stepper: MatStepper; @@ -35,7 +37,8 @@ export class TestrunnerComponent implements OnInit { constructor(private espPortService: EspPortService, private route: ActivatedRoute, - private deviceConfigurationService: DeviceConfigurationService) { + private deviceConfigurationService: DeviceConfigurationService, + private testResultService: TestResultService) { } @@ -64,6 +67,7 @@ export class TestrunnerComponent implements OnInit { if (this.firmwareMessages.length > 0) { console.log("We have a message"); } + this.sendTestResults(this.firmwareMessages); } catch(e) { this.messageArea = this.messageArea + '\n' + message; this.messageCount++; @@ -159,6 +163,53 @@ export class TestrunnerComponent implements OnInit { return "warn"; } + sendTestResults(firmwareMessages: FirmwareMessage[]) { + /* + [ + {"name":"Mac Address","value":"DC:54:75:F0:3F:D0","result":"OK"}, + {"name":"Chip Model","value":"ESP32-S3","result":"OK"}, + {"name":"Chip Revision","value":"0","result":"OK"}, + {"name":"Available Cores","value":"2","result":"OK"}, + {"name":"Heap Size","value":"384kb","result":"OK"}, + {"name":"Free Heap","value":"333kb","result":"OK"}, + {"name":"PSRAM Size","value":"0kb","result":"OK"}, + {"name":"Free PSRAM","value":"0kb","result":"OK"}, + {"name":"Flash Chip Size","value":"4096kb","result":"OK"}, + {"name":"External Flash Card Type","value":"SDSC","result":"OK"}, + {"name":"External Flash Card Size","value":"120MB","result":"OK"}, + {"name":"Build Date","value":"Jun 10 2024","result":"OK"}, + {"name":"Build Time","value":"21:27:56","result":"OK"} + ] + */ + + let isOverallSuccess = true; + let macAddress : string = ""; + firmwareMessages.forEach((message: FirmwareMessage) => { + if (message.result === "NOK") { + isOverallSuccess = false; + } + switch(message.name) { + case "Mac Address": + macAddress = message.value; + break; + } + }); + + let testResult : TestResult = { + mac_address: macAddress, + device_type: this.deviceConfiguration.name, + overall_result: isOverallSuccess ? 'OK' : 'NOK', + additional_info: firmwareMessages + }; + + this.testResultService.sendTestResult(testResult).subscribe(response => { + console.log('Test result sent successfully:', response); + }); + + } + } + + diff --git a/src/app/home/home.component.html b/src/app/home/home.component.html index 0bcf49e..249c86f 100644 --- a/src/app/home/home.component.html +++ b/src/app/home/home.component.html @@ -15,4 +15,6 @@

Device Class

+ + diff --git a/src/app/home/home.component.ts b/src/app/home/home.component.ts index 6c22540..911908b 100644 --- a/src/app/home/home.component.ts +++ b/src/app/home/home.component.ts @@ -1,6 +1,8 @@ import { Component, OnInit } from '@angular/core'; import { DeviceConfiguration } from '../model/device-configuration'; import { DeviceConfigurationService } from '../shared/device-configuration.service'; +import { TestResultService } from '../shared/test-result.service'; +import { TestResult } from '../model/test-result'; @Component({ selector: 'app-home', @@ -11,7 +13,7 @@ export class HomeComponent implements OnInit { deviceConfigurations: DeviceConfiguration[]; - constructor(public deviceConfigurationService: DeviceConfigurationService) { + constructor(public deviceConfigurationService: DeviceConfigurationService, private testResultService: TestResultService) { } @@ -35,6 +37,22 @@ export class HomeComponent implements OnInit { isLocalConfiguration(id: string): boolean { return this.deviceConfigurationService.isLocalConfiguration(id); } + + sendResult() { + const testResult = { + mac_address: '00:1A:2B:3C:4D:5E', + overall_result: 'OK', + device_type: 'DeviceTypeA', + additional_info: { + test1: 'pass', + test2: 'fail' + } + }; + + this.testResultService.sendTestResult(testResult).subscribe(response => { + console.log('Test result sent successfully:', response); + }); + } } diff --git a/src/app/model/firmware-message.ts b/src/app/model/firmware-message.ts index cff5e4e..58a4f06 100644 --- a/src/app/model/firmware-message.ts +++ b/src/app/model/firmware-message.ts @@ -1,8 +1,5 @@ export interface FirmwareMessage { - heapSize: number; - freeHeap: number; - psramSize: number; - freePsram: number; - buildTime: string; - buildDate: string; + name: string; + value: string; + result: string; } diff --git a/src/app/model/test-result.ts b/src/app/model/test-result.ts new file mode 100644 index 0000000..667eda1 --- /dev/null +++ b/src/app/model/test-result.ts @@ -0,0 +1,6 @@ +export interface TestResult { + mac_address: string; + overall_result: 'OK' | 'NOK'; + device_type: string; + [key: string]: any; + } \ No newline at end of file diff --git a/src/app/shared/test-result.service.spec.ts b/src/app/shared/test-result.service.spec.ts new file mode 100644 index 0000000..ccea10f --- /dev/null +++ b/src/app/shared/test-result.service.spec.ts @@ -0,0 +1,16 @@ +import { TestBed } from '@angular/core/testing'; + +import { TestResultService } from './test-result.service'; + +describe('TestResultService', () => { + let service: TestResultService; + + beforeEach(() => { + TestBed.configureTestingModule({}); + service = TestBed.inject(TestResultService); + }); + + it('should be created', () => { + expect(service).toBeTruthy(); + }); +}); diff --git a/src/app/shared/test-result.service.ts b/src/app/shared/test-result.service.ts new file mode 100644 index 0000000..cb4ad45 --- /dev/null +++ b/src/app/shared/test-result.service.ts @@ -0,0 +1,35 @@ +import { Injectable } from '@angular/core'; +import { HttpClient, HttpHeaders } from '@angular/common/http'; +import { Observable, of } from 'rxjs'; +import { catchError } from 'rxjs/operators'; +import { TestResult } from '../model/test-result'; + +@Injectable({ + providedIn: 'root' +}) +export class TestResultService { + + private apiUrl = '/api/rest.php'; // Update with your actual API endpoint + private apiKey = 'yourkey'; // Replace with your generated API key + + constructor(private http: HttpClient) { } + + sendTestResult(result: TestResult): Observable { + const headers = new HttpHeaders({ + 'Content-Type': 'application/json', + 'Authorization': `Bearer ${this.apiKey}` + }); + return this.http.post(this.apiUrl, result, { headers: headers }) + .pipe( + catchError(this.handleError('sendTestResult')) + ); + } + + private handleError(operation = 'operation', result?: T) { + return (error: any): Observable => { + console.error(error); // Log the error for debugging purposes + // Let the app continue by returning an empty result. + return of(result as T); + }; + } +}