Node Meshblu client for XMPP
npm install meshblu-xmpp
var Meshblu = require('meshblu-xmpp');
var config = {
hostname: 'meshblu-xmpp.octoblu.com',
port: 5222,
uuid: 'cf2497d2-7426-46c4-a229-ad789063bf88',
token: 'a0178530f1d15f17ddcae60ae7198fc954c2ef53'
}
var conn = new Meshblu(config);
conn.connect(function(error){
if (error) {
throw error;
}
console.log('Connected');
});
var message = {
"devices": ["*"],
"payload": "duuude"
};
conn.message(message, function(error){
if (error) {
panic(error);
}
console.log('Sent Message');
});
// Message handler
conn.on('message', function(message){
console.log('Message Received: ', message);
});
conn.createSessionToken(config.uuid, {"name": "my token"}, function(error, result){
if (error) {
panic(error);
}
console.log('Create Session Token: ', result);
});
conn.status(function(error, result){
if (error) {
panic(error);
}
console.log('Status:', result);
});
conn.whoami(function(error, device){
if (error) {
panic(error);
}
console.log('Whoami: ', device);
});
var update = {
"$set": {
"type": "device:generic"
}
};
conn.update(config.uuid, update, function(error){
if (error) {
panic(error);
}
console.log('Updated the device');
});
// Register a new device
conn.register({"type": "device:generic"}, function(error, device){
if (error) {
panic(error);
}
console.log('Registered a new Device: ', device);
});
// Subscribe to your own messages to enable recieving them
// conn.unsubscribe takes the same arguments
var subscription = {
"subscriberUuid" : config.uuid,
"emitterUuid": config.uuid,
"type": 'message.received'
};
conn.subscribe(config.uuid, subscription, function(err, result){
console.log('Subscribe: ', result);
});
// Search for devices by a query
var query = {
"type": "device:generic"
};
conn.searchDevices(config.uuid, query, function(err, result){
console.log('Search Devices: ', result);
console.log(err);
});