Skip to content

Commit

Permalink
speech
Browse files Browse the repository at this point in the history
  • Loading branch information
4refr0nt committed Oct 16, 2016
1 parent 4a73362 commit d270ea5
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 1 deletion.
8 changes: 7 additions & 1 deletion README.md
@@ -1,5 +1,11 @@
##### iot-manager-demo
---
##### Demo sketches for [IoT Manager](https://play.google.com/store/apps/details?id=ru.esp8266.iotmanager)

Demo sketches for

##### [IoT Manager for iOS](https://itunes.apple.com/us/app/iot-manager/id1155934877)

##### [IoT Manager for Android](https://play.google.com/store/apps/details?id=ru.esp8266.iotmanager)

---
### pull-requests welcomed!
4 changes: 4 additions & 0 deletions node.js/official-demo/README.md
Expand Up @@ -14,11 +14,15 @@ node boiler.js

- boiler.js
- bilb.js
- chart.js
- demo.js
- display-value.js
- fillgauge.js
- home.js
- linear.js
- simple-btn.js
- speech.js
- toggle.js


## License
Expand Down
101 changes: 101 additions & 0 deletions node.js/official-demo/speech.js
@@ -0,0 +1,101 @@
////////////////////////////////////////////////
//
// Demo for text2speech feature
//
//
// IoT Manager https://play.google.com/store/apps/details?id=ru.esp8266.iotmanager
//
// version : 1.0
// IoT Manager : 1.5.4 and above
//
////////////////////////////////////////////////

////////////////////////////////////////////////
var config = require("./config");
var host = config.host;
var port = config.port;
var user = config.user;
var pass = config.pass;
////////////////////////////////////////////////

var mqtt = require('mqtt');
var opt = {
host : host,
port : port,
username : user,
password : pass,
clientId : 'mqtt-js_' + Math.random().toString(16).substr(2, 8),
protocolId : 'MQTT',
connectTimeout: 3000
};


var deviceID = "device10";
var prefix = "/IoTmanager";
var config = [];
var client = mqtt.connect(opt);

// First line
var widget = "anydata";
var id = "0"

widget = "chart";
id = "0"
config[0] = {
id : id,
widget : widget,
topic : prefix + "/" + deviceID + "/" + widget + id,
widgetConfig: {
type: 'line', // line, bar, horizontalBar, radar, polarArea, doughnut, pie, bubble
maxCount: 20
}
};

client.on('connect', function () {
console.log('Broker connected');
client.subscribe(prefix, { qos : 1 }); // HELLO expected
pubConfig();
});

client.on('error', function () {
console.log('Broker error');
});

client.on('offline', function () {
console.log('Broker offline');
});

client.on('message', function (topic, message) {

console.log("Message arrived: " + topic.toString() + " => " + message.toString());

if (topic.toString() === prefix && message.toString() == "HELLO" ){
console.log('HELLO detected');
pubConfig();
}
pubStatus();

})
////////////////////////////////////////////////
function pubConfig() {
config.forEach(function(item, i, arr) {
client.publish(prefix + "/" + deviceID + "/config", JSON.stringify(item),{ qos : 1 });
});
}
////////////////////////////////////////////////
function pubStatus() {

var x = 20 + Math.round(Math.random() * 4);
// text = 'hello';
text = 'Outside temperature ' + x.toString();
client.publish( config[0].topic+"/status", JSON.stringify({ status: x, speech: text }) );

console.log('Publish');
}
////////////////////////////////////////////////
// run main
console.log('Start');

setInterval(function() {
pubStatus();
}, 10000);

0 comments on commit d270ea5

Please sign in to comment.