var express = require('express');
var app = express();
var server = require('http').createServer(app);
var io = require('socket.io')(server);
var mkdirp = require('mkdirp');
var appPort = process.env.APPPORT || "5000"
app.set('views', __dirname + '/app/views')
app.set('view engine', 'pug')
app.use(express.static(__dirname + '/public'))
server.listen(appPort, function () {
console.log('Server listening at port %d', appPort);
});
//App components
var routes = require('./app/routes');
app.use('/', routes);
io.attach(server);
var socket = require('./app/socket');
socket.start(io);
#include "ets_sys.h"
#include "user_interface.h"
#include "osapi.h"
#include "gpio.h"
#include "os_type.h"
#include <espconn.h>
/* Change to desired SSID name */
const char ssid[32] = "wwwdlan";
/* Enter the Password of the AP */
const char password[32] = "wertwert5";
/* Will hold the SSID and Password Information */
struct station_config stationConf;
struct espconn sendResponse; //udp
esp_udp udp;
// timer
os_timer_t send_udp_device_info;
/******************************************************************************
* FunctionName : user_init
* Description : entry of user application, init user function here
* Parameters : none
* Returns : none
*******************************************************************************/
void send_dev_info(void *pArg)
{
int err;
sendResponse.type = ESPCONN_UDP;
sendResponse.state = ESPCONN_NONE;
sendResponse.proto.udp = &udp;
IP4_ADDR((ip_addr_t *)sendResponse.proto.udp->remote_ip, 239, 255, 255, 250);
sendResponse.proto.udp->remote_port = 4000; // Remote port
err = espconn_create(&sendResponse);
err = espconn_send(&sendResponse, "hi123", 5);
err = espconn_delete(&sendResponse);
}
void user_init(void)
{
/* Select UART 0 and configure the baud rate to 9600 */
uart_div_modify(0, UART_CLK_FREQ / 9600);
os_printf("Demo Example - ESP8266 as Station\r\n");
/* Configure the ESP8266 to Station Mode */
wifi_set_opmode( STATION_MODE );
/* Copy the SSID and Password Info to the structure */
os_memcpy(&stationConf.ssid, ssid, 32);
os_memcpy(&stationConf.password, password, 32);
/* Configure the station to connect to the following AP */
wifi_station_set_config(&stationConf);
/* Connects to the AP */
wifi_station_connect();
os_timer_setfn(&send_udp_device_info, send_dev_info, NULL);
os_timer_arm(&send_udp_device_info, 10*1000, 1);
}
var PORT = 4000;
var MULTICAST_ADDR = '239.255.255.250';
var dgram = require('dgram');
var client = dgram.createSocket('udp4');
client.on('listening', function () {
var address = client.address();
console.log('UDP Client listening on ' + address.address + ":" + address.port);
});
client.on('message', function (message, rinfo) {
console.log('Message from: ' + rinfo.address + ':' + rinfo.port + ' - ' + message);
});
client.bind(PORT, function () {
client.addMembership(MULTICAST_ADDR);
});
npm install -g @angular/cli
npm i --save supervisor
"scripts": {
"test": "node_modules\\\\.bin\\\\supervisor index.js",
"start": "node index.js"
},
npm test
var getDataFromDatabase = function () {
var arr = []
var con = mysql.createConnection(conf.config);
con.connect(function (err) {
if(err) throw err;
con.query("SELECT DID, DName FROM Device")
.on('result', function (data) {
arr.push(data)
})
.on('end', function () {
return callback(null, arr);
})
.on('error', function(err){
return callback (err, null);
});
}
module.exports = {
getDataFromDatabase
}
var fromDB = require(./modulName);
fromDB.getDataFromDatabase(function(err, result){
if(err){
console.log(err);
} else {
console.log(result);
}
})
var getDataFromDatabase = function (callback) {
return new Promise((resolve, reject) => {
var arr = []
var con = mysql.createConnection(conf.config);
con.connect(function (err) {
if (err) throw err;
con.query("SELECT DID, DName FROM Device")
.on('result', function (data) {
arr.push(data)
})
.on('end', function () {
return resolve(arr);
})
.on('error', function (err) {
return reject(err);
})
});
})
}
module.exports = {
getDataFromDatabase
}
var fromDB = require("./modulName");
fromDB.getDataFromDatabase()
.then(result =>{
console.log(result);
},(err)=>{
console.log(err);
})
var getDataFromDatabase = async function (callback) {
return new Promise((resolve, reject) => {
var arr = []
var con = mysql.createConnection(conf.config);
con.connect(function (err) {
if (err) throw err;
con.query("SELECT DID, DName FROM Device")
.on('result', function (data) {
arr.push(data)
})
.on('end', function () {
return callback(null, arr);
})
.on('error', function (err) {
return callback(err, null);
})
});
})
}
module.exports = {
getDataFromDatabase
}
var fromDB = require("./modulName");
var test = await fromDB.getDataFromDatabase();
var winston = require('winston');
//logger is configured to save output to log file
var logger = new (winston.Logger)({
level: level,
transports: [
new (winston.transports.File)({
filename: '' + logdir + "/" + timeAct + '_' + program.server + '.log',
json: false
})
]
});
//add console output if debug is on
if (program.debug) {
logger.add(winston.transports.Console, { json: false });
} else {
if (program.debugfile) {
logger = new (winston.Logger)({
level: 'debug',
transports: [
new (winston.transports.File)({
filename: '' + logdir + "/" + timeAct + "_" + program.server + '_debug_.log',
json: false
})
]
});
} else {
//if error, write to console
logger.add(winston.transports.Console, {
level: 'error',
json: false
});
}
}