forked from Tank/braga
add config
This commit is contained in:
parent
dbcedd2348
commit
0ad07a1ad6
60
nginx.conf
60
nginx.conf
@ -1,5 +1,65 @@
|
|||||||
lua_package_path "/var/www/blog/?.lua;/var/www/braga/?.lua;/var/www/appphotos/?.lua;/var/www/apihh/?.lua;;";
|
lua_package_path "/var/www/blog/?.lua;/var/www/braga/?.lua;/var/www/appphotos/?.lua;/var/www/apihh/?.lua;;";
|
||||||
lua_code_cache off;
|
lua_code_cache off;
|
||||||
|
|
||||||
|
worker_processes auto;
|
||||||
|
worker_rlimit_nofile 16000;
|
||||||
|
error_log /home/zoviet/lock/logs/nginx_error.log debug;
|
||||||
|
|
||||||
|
|
||||||
|
events {
|
||||||
|
worker_connections 1000;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Работа с замками через TCP сокеты
|
||||||
|
|
||||||
|
stream {
|
||||||
|
lua_package_path "./home/zoviet/lock/?.lua;;";
|
||||||
|
lua_code_cache off;
|
||||||
|
|
||||||
|
init_by_lua '
|
||||||
|
json = require "cjson";
|
||||||
|
redis = require "resty.redis"
|
||||||
|
';
|
||||||
|
|
||||||
|
server {
|
||||||
|
listen 4999;
|
||||||
|
set $redis_host "127.0.0.1";
|
||||||
|
set $redis_port "6379";
|
||||||
|
error_log /home/zoviet/lock/logs/sockets.log debug;
|
||||||
|
content_by_lua_file /home/zoviet/lock/tcp.lua;
|
||||||
|
}
|
||||||
|
|
||||||
|
server {
|
||||||
|
listen 21;
|
||||||
|
proxy_pass 213.108.200.242:21;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# TCP сокет для обмена с замками
|
||||||
|
|
||||||
|
server {
|
||||||
|
listen 4333 ssl;
|
||||||
|
server_name hh24lock.ru;
|
||||||
|
|
||||||
|
ssl_certificate /etc/letsencrypt/live/hh24lock.ru/fullchain.pem;
|
||||||
|
ssl_certificate_key /etc/letsencrypt/live/hh24lock.ru/privkey.pem;
|
||||||
|
|
||||||
|
ssl_session_cache shared:SSL:1m;
|
||||||
|
ssl_session_timeout 5m;
|
||||||
|
|
||||||
|
ssl_ciphers HIGH:!aNULL:!MD5;
|
||||||
|
ssl_prefer_server_ciphers on;
|
||||||
|
|
||||||
|
set $redis_host "127.0.0.1";
|
||||||
|
set $redis_port "6379";
|
||||||
|
|
||||||
|
error_log /home/zoviet/lock/logs/socket.log;
|
||||||
|
|
||||||
|
location / {
|
||||||
|
default_type 'plain/text';
|
||||||
|
content_by_lua_file /home/zoviet/lock/socket.lua;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
server {
|
server {
|
||||||
listen 80;
|
listen 80;
|
||||||
|
|||||||
31
tcp.lua
Normal file
31
tcp.lua
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
local json = require('cjson.safe')
|
||||||
|
local base64 = require('base64')
|
||||||
|
local guid = nil
|
||||||
|
|
||||||
|
-- Расшифровка сообщения от устройства
|
||||||
|
|
||||||
|
local function decode(rec)
|
||||||
|
rec = base64.decode(rec)
|
||||||
|
ngx.log(ngx.INFO, rec)
|
||||||
|
return json.decode(rec)
|
||||||
|
end
|
||||||
|
|
||||||
|
local sock = assert(ngx.req.socket(true),'no socket')
|
||||||
|
sock:settimeout(10000) -- one second timeout
|
||||||
|
local rec = sock:receive() -- read a line from downstream
|
||||||
|
|
||||||
|
|
||||||
|
if rec == nil then
|
||||||
|
ngx.log(ngx.NOTICE, 'Empty data')
|
||||||
|
return ngx.exit(444)
|
||||||
|
else
|
||||||
|
rec = decode(rec)
|
||||||
|
local res = db.add({['guid']=rec.id,['type']='bme',['alt']=rec.bme.alt,['temp']=rec.bme.temp,['press']=rec.bme.press})
|
||||||
|
ngx.log(ngx.NOTICE, res)
|
||||||
|
res = db.add({['guid']=rec.id,['type']='dht',['humi']=rec.dht.humi,['temp']=rec.dht.temp})
|
||||||
|
ngx.log(ngx.NOTICE, res)
|
||||||
|
res = db.add({['guid']=rec.id,['type']='solar',['uf']=rec.uf})
|
||||||
|
ngx.log(ngx.NOTICE, res)
|
||||||
|
sock:send(base64.encode(json.encode(rec)))
|
||||||
|
end
|
||||||
|
|
||||||
Loading…
x
Reference in New Issue
Block a user