This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// you can define router | |
// and add a switch with all routes as a child of a "Main layout component" called app | |
import React from 'react'; | |
import { render } from 'react-dom'; | |
import createHistory from 'history/createBrowserHistory'; | |
import { Router, Route, Redirect, Switch } from 'react-router-dom'; | |
const history = createHistory(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var mqtt = require('mqtt') | |
var client = mqtt.connect('mqtt://test.mosquitto.org') | |
client.on('connect', function () { | |
client.subscribe('presence') | |
client.publish('presence', 'Hello mqtt') | |
}) | |
client.on('message', function (topic, message) { | |
// message is Buffer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const mqtt = require('mqtt'); | |
class MqttHandler { | |
constructor() { | |
this.mqttClient = null; | |
this.host = 'YOUR_HOST'; | |
this.username = 'YOUR_USER'; // mqtt credentials if these are needed to connect | |
this.password = 'YOUR_PASSWORD'; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var express = require("express"); | |
var bodyParser = require("body-parser"); | |
var app = express(); | |
var mqttHandler = require('./mqtt_handler'); | |
app.use(bodyParser.json()); | |
app.use(bodyParser.urlencoded({ extended: true })) | |
var mqttClient = new mqttHandler(); | |
mqttClient.connect(); |