Copyright © 2014 Michael Schloh von Bennewitz Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the document entitled “fdl-1.3.txt”
Presented by: Michael Schloh von Bennewitz
Download at: dev.europalab.com/iotintmob/
// Load HTTP module
var httpmod = require('http');
// Create HTTP server
httpmod.createServer(function (req, res) {
// Content header
res.writeHead(200, {'content-type': 'text/plain'});
// Write message and signal communication is complete
res.end("Hello, Tizen World!\n");
}).listen(8088);
// This presentation is very boring
console.log('Server running on 8088');
Run this NodeJS code on your smartphone!
// Simple publish client
var mqtt = require('mqtt'), locli = mqtt.createClient();
locli.publish('messages', 'Mqtt');
locli.publish('messages', 'is pretty cool');
locli.publish('messages', 'remember that!', {retain: true});
locli.end();
Publishing messages via MQTT to the broker
// Simple subscribe client
var mqtt = require('mqtt') , locli = mqtt.createClient();
locli.subscribe('messages');
locli.publish('messages', 'Hello from me!');
locli.on('message', function(topic, message) {
console.log(message);
});
// disable automatic reconnect
locli.options.reconnectPeriod = 0;
Subscribing to topics via MQTT from the broker