Skip to content

Commit

Permalink
NOISSUE - Add OPC-UA page
Browse files Browse the repository at this point in the history
Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
  • Loading branch information
manuio committed Dec 4, 2019
1 parent ad43daa commit 429c6fa
Show file tree
Hide file tree
Showing 41 changed files with 583 additions and 140 deletions.
2 changes: 1 addition & 1 deletion src/app/@theme/components/header/header.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { LayoutService } from 'app/@core/utils';
import { Subject, Subscription } from 'rxjs';
import { Router } from '@angular/router';

import { User } from 'app/common/interfaces/models';
import { User } from 'app/common/interfaces/mainflux.interface';
import { UsersService } from 'app/common/services/users/users.service';

@Component({
Expand Down
2 changes: 2 additions & 0 deletions src/app/common/common.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { BootstrapService } from './services/bootstrap/bootstrap.service';
import { ChannelsService } from './services/channels/channels.service';
import { GatewaysService } from './services/gateways/gateways.service';
import { LoraService } from './services/lora/lora.service';
import { OpcuaService } from './services/opcua/opcua.service';
import { MessagesService } from './services/messages/messages.service';
import { MqttManagerService } from './services/mqtt/mqtt.manager.service';
import { NotificationsService } from './services/notifications/notifications.service';
Expand All @@ -20,6 +21,7 @@ import { HTTP_INTERCEPTORS } from '@angular/common/http';
ChannelsService,
GatewaysService,
LoraService,
OpcuaService,
MessagesService,
MqttManagerService,
NotificationsService,
Expand Down
22 changes: 22 additions & 0 deletions src/app/common/interfaces/bootstrap.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
export interface Config {
thing_id: string;
thing_key: string;
channels: Array<string>;
external_id: string;
external_key: string;
content: string;
state: number;
}

export interface ConfigContent {
log_level: string;
http_port: string;
mqtt_url: string;
edgex_url: string;
wowza_url: string;
}

export interface ConfigUpdate {
content: string;
name: string;
}
15 changes: 15 additions & 0 deletions src/app/common/interfaces/gateway.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export interface GatewayMetadata {
ctrlChannelID?: string;
dataChannelID?: string;
gwPassword?: string;
mac?: string;
cfgID?: string;
type?: string;
}

export interface Gateway {
id?: string;
key?: string;
name?: string;
metadata?: GatewayMetadata;
}
31 changes: 31 additions & 0 deletions src/app/common/interfaces/mainflux.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
export interface User {
email?: string;
password?: string;
picture?: string;
metadata?: Object;
}

export interface Channel {
id?: string;
name?: string;
metadata?: any;
}

export interface Thing {
id?: string;
key?: string;
name?: string;
metadata?: any;
}

export interface Message {
bn: string;
bt: number;
bu: string;
bver: number;
n: string;
t: number;
u: string;
v: number;
vs: string;
}
70 changes: 0 additions & 70 deletions src/app/common/interfaces/models.ts

This file was deleted.

15 changes: 15 additions & 0 deletions src/app/common/interfaces/opcua.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export interface OpcuaMetadata {
type?: string;
opcua: {
serverURI?: string,
nodeID?: string,
};
channelID?: string;
}

export interface OpcuaNode {
name?: string;
id?: string;
key?: string;
metadata?: OpcuaMetadata;
}
3 changes: 2 additions & 1 deletion src/app/common/services/bootstrap/bootstrap.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import 'rxjs/add/operator/switchMap';
import 'rxjs/add/operator/map';

import { environment } from 'environments/environment';
import { Config, ConfigContent, ConfigUpdate, Gateway } from 'app/common/interfaces/models';
import { Gateway } from 'app/common/interfaces/gateway.interface';
import { Config, ConfigContent, ConfigUpdate } from 'app/common/interfaces/bootstrap.interface';
import { NotificationsService } from 'app/common/services/notifications/notifications.service';
import { ThingsService } from 'app/common/services/things/things.service';

Expand Down
2 changes: 1 addition & 1 deletion src/app/common/services/channels/channels.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Injectable } from '@angular/core';
import 'rxjs/add/operator/map';

import { environment } from 'environments/environment';
import { Channel } from 'app/common/interfaces/models';
import { Channel } from 'app/common/interfaces/mainflux.interface';
import { NotificationsService } from 'app/common/services/notifications/notifications.service';


Expand Down
4 changes: 2 additions & 2 deletions src/app/common/services/gateways/gateways.service.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Injectable } from '@angular/core';
import { v4 as uuid } from 'uuid';

import { Gateway } from 'app/common/interfaces/models';
import { Channel } from 'app/common/interfaces/models';
import { Gateway } from 'app/common/interfaces/gateway.interface';
import { Channel } from 'app/common/interfaces/mainflux.interface';
import { ThingsService } from 'app/common/services/things/things.service';
import { ChannelsService } from 'app/common/services/channels/channels.service';
import { BootstrapService } from 'app/common/services/bootstrap/bootstrap.service';
Expand Down
2 changes: 1 addition & 1 deletion src/app/common/services/messages/messages.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class MessagesService {
getMessages(channel: string, key: string) {
const params = new HttpParams()
.set('offset', '0')
.set('limit', '500');
.set('limit', '1000');

const headers = new HttpHeaders({
'Authorization': key,
Expand Down
2 changes: 1 addition & 1 deletion src/app/common/services/mqtt/mqtt.manager.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Injectable, EventEmitter } from '@angular/core';
import { MqttService, IMqttMessage, MqttConnectionState } from 'ngx-mqtt';
import { NotificationsService } from 'app/common/services/notifications/notifications.service';

import { Message } from 'app/common/interfaces/models';
import { Message } from 'app/common/interfaces/mainflux.interface';
import { Subscription } from 'rxjs';

@Injectable()
Expand Down
107 changes: 107 additions & 0 deletions src/app/common/services/opcua/opcua.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import { Injectable } from '@angular/core';

import { OpcuaNode } from 'app/common/interfaces/opcua.interface';
import { ThingsService } from 'app/common/services/things/things.service';
import { ChannelsService } from 'app/common/services/channels/channels.service';
import { NotificationsService } from 'app/common/services/notifications/notifications.service';

@Injectable()
export class OpcuaService {
typeOpcua = 'opcua';
typeOpcuaServer = 'OPC-UA-Server';

constructor(
private thingsService: ThingsService,
private channelsService: ChannelsService,
private notificationsService: NotificationsService,
) { }

getNode(id: string) {
return this.thingsService.getThing(id);
}

getNodes(offset: number, limit: number) {
return this.thingsService.getThings(offset, limit, this.typeOpcua);
}

addNode(node: any) {
const chanReq = {
name: `${this.typeOpcuaServer}-${node.name}`,
metadata: {
type: this.typeOpcua,
opcua: {
serverURI: node.serverURI,
},
},
};

// TODO - Check if channel exist
return this.channelsService.addChannel(chanReq).map(
respChan => {
const chanID = respChan.headers.get('location').replace('/channels/', '');
const nodeReq: OpcuaNode = {
name: node.name,
metadata: {
type: this.typeOpcua,
channelID: chanID,
opcua: {
nodeID: node.nodeID,
serverURI: node.serverURI,
},
},
};

this.thingsService.addThing(nodeReq).subscribe(
respThing => {
const thingID = respThing.headers.get('location').replace('/things/', '');
this.channelsService.connectThing(chanID, thingID).subscribe(
respCon => {
this.notificationsService.success('OPC-UA Node successfully created', '');
},
err => {
this.thingsService.deleteThing(thingID).subscribe();
this.channelsService.deleteChannel(chanID).subscribe();
},
);
},
err => {
this.channelsService.deleteChannel(chanID).subscribe();
},
);
},
);
}

editNode(node: any) {
const nodeReq: OpcuaNode = {
id: node.id,
name: node.name,
metadata: {
type: this.typeOpcua,
opcua: {
serverURI: node.serverURI,
nodeID: node.nodeID,
},
},
};

return this.thingsService.editThing(nodeReq).map(
resp => {
this.notificationsService.success('OPC-UA Node successfully edited', '');
},
);
}

deleteNode(node: any) {
const channelID = node.metadata.channelID;
return this.channelsService.deleteChannel(channelID).map(
respChan => {
this.thingsService.deleteThing(node.id).subscribe(
respThing => {
this.notificationsService.success('OPC-UA Node successfully deleted', '');
},
);
},
);
}
}
2 changes: 1 addition & 1 deletion src/app/common/services/things/things.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Injectable } from '@angular/core';
import 'rxjs/add/operator/map';

import { environment } from 'environments/environment';
import { Thing } from 'app/common/interfaces/models';
import { Thing } from 'app/common/interfaces/mainflux.interface';
import { NotificationsService } from 'app/common/services/notifications/notifications.service';

@Injectable()
Expand Down
2 changes: 1 addition & 1 deletion src/app/common/services/users/users.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';

import { environment } from 'environments/environment';
import { User } from 'app/common/interfaces/models';
import { User } from 'app/common/interfaces/mainflux.interface';
import { NotificationsService } from 'app/common/services/notifications/notifications.service';

@Injectable()
Expand Down
2 changes: 1 addition & 1 deletion src/app/common/store/channels.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Injectable } from '@angular/core';
import { action, observable } from 'mobx';

import { ChannelsService } from 'app/common/services/channels/channels.service';
import { Channel } from 'app/common/interfaces/models';
import { Channel } from 'app/common/interfaces/mainflux.interface';
import { UiStore } from './ui.store';

@Injectable()
Expand Down
2 changes: 1 addition & 1 deletion src/app/common/store/gateways.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Injectable } from '@angular/core';
import { action, observable } from 'mobx';

import { GatewaysService } from 'app/common/services/gateways/gateways.service';
import { Gateway } from 'app/common/interfaces/models';
import { Gateway } from 'app/common/interfaces/gateway.interface';
import { UiStore } from './ui.store';

@Injectable()
Expand Down
5 changes: 5 additions & 0 deletions src/app/pages/pages-menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ export const MENU_ITEMS: NbMenuItem[] = [
icon: 'radio-outline',
link: '/pages/things/lora',
},
{
title: 'OPC-UA',
icon: 'globe-outline',
link: '/pages/things/opcua',
},
{
title: 'Gateways',
icon: 'hard-drive-outline',
Expand Down
Loading

0 comments on commit 429c6fa

Please sign in to comment.