Guest User

Untitled

a guest
Jun 26th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. const mqtt = require('mqtt');
  2. const Client = require("ibmiotf");
  3. const appClientConfig = require('../config').watsonIoTConfigs;
  4. const rp = require('request-promise');
  5. let appClient = new Client.IotfApplication(appClientConfig);
  6. appClient.connect();
  7.  
  8. let myClient = new mqtt.connect('tcp://myserver', {
  9. clientId: 'id222s2',
  10. username: 'username',
  11. password: 'password',
  12. port: 221112,
  13. will: {
  14. topic: 'server_disconnected',
  15. payload: "Server disconnected!, please call technical support",
  16. qos: 2
  17. }
  18. });
  19.  
  20. appClient.on("connect", () => {
  21. console.log('ibmiot connected');
  22. appClient.subscribeToDeviceStatus();
  23. appClient.subscribeToDeviceEvents();
  24. });
  25.  
  26. myClient.on('message', function (topic, message) {
  27. appClient.publish("topic1", "json", 'something') // here the ibmiotf disconnect
  28. }
Add Comment
Please, Sign In to add comment