Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function main() {
// init hardware
setBrightness(100);
setAll(0, 0, 0);
console.info("UnicornHAT initilized");
let servient = new Servient();
servient.addServer(new HttpServer());
servient.addServer(new CoapServer());
// get WoT object for privileged script
servient.start().then( (myWoT) => {
console.info("RaspberryServient started");
try {
let template: WoT.ThingFragment = { name: "Unicorn" };
let thing = myWoT.produce(template);
unicorn = thing;
unicorn
.addProperty(
"brightness",
public constructor(config? : any) {
super();
Object.assign(this.config, config);
console.info("MyServient configured with", this.config);
let coapServer = (typeof this.config.coap.port === "number") ? new CoapServer(this.config.coap.port) : new CoapServer();
this.addServer(coapServer);
this.addClientFactory(new CoapClientFactory());
// loads credentials from the configuration
this.addCredentials(this.config.credentials);
}
// apply config
if (typeof this.config.servient.staticAddress === "string") {
Helpers.setStaticAddress(this.config.servient.staticAddress);
}
if (!this.config.servient.clientOnly) {
if (this.config.http !== undefined) {
let httpServer = new HttpServer(this.config.http);
this.addServer(httpServer);
// re-use httpServer (same port)
this.addServer(new WebSocketServer(httpServer));
}
if (this.config.coap !== undefined) {
// var to reuse below in CoapClient
var coapServer = (typeof this.config.coap.port === "number") ? new CoapServer(this.config.coap.port) : new CoapServer();
this.addServer(coapServer);
}
if (this.config.mqtt !== undefined) {
let mqttBrokerServer = new MqttBrokerServer(this.config.mqtt.broker,
(typeof this.config.mqtt.username === "string") ? this.config.mqtt.username : undefined,
(typeof this.config.mqtt.password === "string") ? this.config.mqtt.password : undefined,
(typeof this.config.mqtt.clientId === "string") ? this.config.mqtt.clientId : undefined,
(typeof this.config.mqtt.protocolVersion === "number") ? this.config.mqtt.protocolVersion : undefined);
this.addServer(mqttBrokerServer);
}
}
this.addClientFactory(new FileClientFactory());
this.addClientFactory(new HttpClientFactory(this.config.http));
this.addClientFactory(new HttpsClientFactory(this.config.http));
this.addClientFactory(new CoapClientFactory(coapServer));