merge
commit
7538a468a7
|
@ -0,0 +1,2 @@
|
|||
server/node_modules
|
||||
server/db
|
4
init.lua
4
init.lua
|
@ -8,9 +8,9 @@ local node = minetest.register_node("connected:iotswitch", {
|
|||
groups = {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=3},
|
||||
on_rightclick = function (pos, node)
|
||||
print("punch")
|
||||
minetest.after(5, function()
|
||||
minetest.after(1, function()
|
||||
http_api.fetch({
|
||||
url = "http://localhost:3000/resources/feedsonoff",
|
||||
url = "http://localhost:8088/punch",
|
||||
timeout = 1
|
||||
},
|
||||
function (res)
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
"name": "connectedJS",
|
||||
"version": "0.1.0",
|
||||
"dependencies": {
|
||||
"mosca": "^0.29.0"
|
||||
"express": "^4.14.0",
|
||||
"mqtt": "^2.0.1",
|
||||
"ponte": "~0.0.16"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
var mosca = require('mosca');
|
||||
var settings = {
|
||||
var mosca = require('mosca')
|
||||
|
||||
var moscaSettings = {
|
||||
port: 1883
|
||||
};
|
||||
|
||||
var server = new mosca.Server(settings);
|
||||
var server = new mosca.Server(moscaSettings);
|
||||
server.on('ready', setup);
|
||||
|
||||
server.on('clientConnected', function(client) {
|
||||
console.log('client connected', client.id);
|
||||
|
@ -14,9 +16,23 @@ server.on('published', function(packet, client) {
|
|||
console.log('Published', packet.payload);
|
||||
});
|
||||
|
||||
server.on('ready', setup);
|
||||
|
||||
// fired when the mqtt server is ready
|
||||
function setup() {
|
||||
console.log('Mosca server is up and running');
|
||||
console.log('Mosca server is up and running')
|
||||
}
|
||||
|
||||
var mqtt = require('mqtt')
|
||||
//var client = mqtt.connect()
|
||||
var client = mqtt.connect({ port: 1883, host: '127.0.0.1', keepalive: 10000});
|
||||
|
||||
var express = require('express');
|
||||
var app = express();
|
||||
|
||||
app.get('/punch', function (req, res) {
|
||||
res.send('Punch!!!');
|
||||
client.publish('punch', 'message root punch')
|
||||
});
|
||||
|
||||
app.listen(8088, function () {
|
||||
console.log('Example app listening on port 8088!');
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue