Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
H
hdg_mqtt
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
杨苏杭
hdg_mqtt
Commits
a1d5943b
Commit
a1d5943b
authored
Sep 27, 2018
by
banice
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ac报警信息缓存至redis,未同步到mysql
parent
dbaa101f
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
299 additions
and
7 deletions
+299
-7
app/Http/Controllers/ac/AlarmController.php
+35
-4
bootstrap/app.php
+1
-0
config/redis_key.php
+14
-0
readme.md
+1
-1
routes/web.php
+1
-1
src/box/SearchModel.php
+14
-1
src/box/ac/Alarm.php
+233
-0
No files found.
app/Http/Controllers/ac/AlarmController.php
View file @
a1d5943b
...
...
@@ -14,24 +14,54 @@ use App\Providers\RedisServiceProvider;
use
Illuminate\Http\Request
;
use
Illuminate\Support\Facades\Log
;
use
Illuminate\Support\ServiceProvider
;
use
src\box\ac\Alarm
;
use
src\box\Box
;
use
Validator
;
class
AlarmController
extends
Controller
{
public
function
post
(
Request
$request
)
public
function
post
(
Request
$request
,
Box
$box
,
Alarm
$alarm
)
{
app
()
->
register
(
RedisServiceProvider
::
class
);
$boxCode
=
$request
->
get
(
'box_code'
);
$payload
=
$request
->
get
(
'payload'
);
Log
::
debug
(
$request
->
all
());
$redis
=
app
(
'Redis'
);
if
(
$redis
instanceof
\Redis
)
{
Log
::
debug
(
$payload
);
$validator
=
Validator
::
make
(
$payload
,
[
'sensor_bean'
=>
'array'
,
'sensor_bean_count'
=>
'required|integer'
,
'box_num'
=>
'required|integer'
,
'sensor_smoke'
=>
'required|array'
]);
if
(
$validator
->
fails
()
===
true
)
{
Log
::
error
(
$validator
->
errors
()
->
first
(),
$request
->
all
());
return
;
}
if
(
$box
->
searchByCodeNum
(
$boxCode
,
$payload
[
'box_num'
],
[
'id'
])
===
false
)
{
Log
::
error
(
'ac alarm can not find box_id by code and num'
,
$request
->
all
());
return
;
}
$boxId
=
$box
->
getValue
(
'id'
);
$sensorSmoke
=
$payload
[
'sensor_smoke'
];
$sensorBean
=
$payload
[
'sensor_bean'
];
$alarm
->
setBoxId
(
$boxId
);
$alarm
->
setBlackSmoke
(
$sensorSmoke
[
'black_smoke'
]);
$alarm
->
setWhiteSmoke
(
$sensorSmoke
[
'white_smoke'
]);
$alarm
->
setHumidity
(
array_column
(
$sensorBean
,
'humidity'
));
$alarm
->
setTemperature
(
array_column
(
$sensorBean
,
'temperature'
));
$alarm
->
setSensorState
(
array_column
(
$sensorBean
,
'sensor_state'
));
$alarm
->
setRetain
(
array_column
(
$sensorBean
,
'retain'
));
$alarm
->
setAcRetain
(
$sensorSmoke
[
'retain'
]);
$alarm
->
setDeviceState
(
$sensorSmoke
[
'device_state'
]);
$alarm
->
updateAllToRedis
();
//todo 数据库更新
}
}
\ No newline at end of file
bootstrap/app.php
View file @
a1d5943b
...
...
@@ -29,6 +29,7 @@ $app->withEloquent();
$app
->
configure
(
'logging'
);
$app
->
configure
(
'database'
);
$app
->
configure
(
'redis_key'
);
/*
...
...
config/redis_key.php
0 → 100644
View file @
a1d5943b
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/9/27
* Time: 上午11:23
*/
return
[
'AC_ALARM'
=>
'hdg:ac:alarm:hash'
];
readme.md
View file @
a1d5943b
...
...
@@ -3,7 +3,7 @@
## redis 字典
*
ac报警信息
###
ac报警信息
`key:'hdg:ac:alarm:hash`
...
...
routes/web.php
View file @
a1d5943b
...
...
@@ -24,10 +24,10 @@ $router->group(['middleware' => ['mqtt']], function () use ($router) {
$router
->
post
(
'ac/state'
,
'ac\StateController@post'
);
$router
->
post
(
'door/lock/version'
,
'door\LockController@version'
);
$router
->
post
(
'door/state'
,
'door\StateController@post'
);
$router
->
post
(
'ac/alarm/info'
,
'ac\AlarmController@post'
);
});
$router
->
post
(
'ac/alarm/info'
,
'ac\AlarmController@post'
);
$router
->
post
(
'box/init'
,
'door\InitController@init'
);
...
...
src/box/SearchModel.php
View file @
a1d5943b
...
...
@@ -25,7 +25,20 @@ trait SearchModel
*/
public
function
searchByCode
(
string
$code
,
array
$parameters
=
[])
:
bool
{
$this
->
boxModel
=
BoxModel
::
where
(
'code'
,
$code
)
->
first
(
$parameters
);
$this
->
boxModel
=
BoxModel
::
where
([[
'code'
,
$code
],
[
'box_type'
,
0
]])
->
first
(
$parameters
);
return
$this
->
boxModel
===
null
?
false
:
true
;
}
/**
* @param string $code
* @param int $num
* @param array $parameters
* @return bool
*/
public
function
searchByCodeNum
(
string
$code
,
int
$num
,
array
$parameters
=
[])
:
bool
{
$this
->
boxModel
=
BoxModel
::
where
([[
'code'
,
$code
],
[
'box_type'
,
$num
]])
->
first
(
$parameters
);
return
$this
->
boxModel
===
null
?
false
:
true
;
}
...
...
src/box/ac/Alarm.php
0 → 100644
View file @
a1d5943b
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/9/27
* Time: 上午10:52
*/
namespace
src\box\ac
;
use
Illuminate\Support\Facades\Redis
;
class
Alarm
{
private
$boxId
;
/**
* @var array 湿度
*/
private
$humidity
=
[];
/**
* @var array 温度
*/
private
$temperature
=
[];
private
$sensorState
=
[];
/**
* @var array 保留
*/
private
$retain
=
[];
/**
* @var int 白烟
*/
private
$whiteSmoke
=
0
;
/**
* @var int 黑烟
*/
private
$blackSmoke
=
0
;
/**
* @var int 设备状态
*/
private
$deviceState
=
0
;
/**
* @var int 预留
*/
private
$acRetain
=
0
;
/**
* 更新所有报警数据至redis
*/
public
function
updateAllToRedis
()
{
$redis
=
app
(
'Redis'
);
$update
=
[];
$i
=
1
;
foreach
([
'humidity'
=>
$this
->
humidity
,
'temperature'
=>
$this
->
temperature
,
'sensor_state'
=>
$this
->
sensorState
,
'retain'
=>
$this
->
retain
,
]
as
$key
=>
$items
)
{
$i
=
1
;
foreach
(
$items
as
$item
)
{
$update
[
$key
.
'_'
.
$i
++
]
=
$item
;
}
}
$update
[
'white_smoke'
]
=
$this
->
whiteSmoke
;
$update
[
'black_smoke'
]
=
$this
->
blackSmoke
;
$update
[
'device_state'
]
=
$this
->
deviceState
;
$update
[
'retain'
]
=
$this
->
acRetain
;
if
(
$redis
instanceof
\Redis
)
{
$redis
->
hMset
(
config
(
'redis_key.AC_ALARM'
)
.
':'
.
$this
->
boxId
,
$update
);
}
}
/**
* @return array
*/
public
function
getHumidity
()
:
array
{
return
$this
->
humidity
;
}
/**
* @param array $humidity
*/
public
function
setHumidity
(
array
$humidity
)
:
void
{
$this
->
humidity
=
$humidity
;
}
/**
* @return array
*/
public
function
getTemperature
()
:
array
{
return
$this
->
temperature
;
}
/**
* @param array $temperature
*/
public
function
setTemperature
(
array
$temperature
)
:
void
{
$this
->
temperature
=
$temperature
;
}
/**
* @return array
*/
public
function
getSensorState
()
:
array
{
return
$this
->
sensorState
;
}
/**
* @param array $sensorState
*/
public
function
setSensorState
(
array
$sensorState
)
:
void
{
$this
->
sensorState
=
$sensorState
;
}
/**
* @return array
*/
public
function
getRetain
()
:
array
{
return
$this
->
retain
;
}
/**
* @param array $retain
*/
public
function
setRetain
(
array
$retain
)
:
void
{
$this
->
retain
=
$retain
;
}
/**
* @return int
*/
public
function
getWhiteSmoke
()
:
int
{
return
$this
->
whiteSmoke
;
}
/**
* @param int $whiteSmoke
*/
public
function
setWhiteSmoke
(
int
$whiteSmoke
)
:
void
{
$this
->
whiteSmoke
=
$whiteSmoke
;
}
/**
* @return int
*/
public
function
getBlackSmoke
()
:
int
{
return
$this
->
blackSmoke
;
}
/**
* @param int $blackSmoke
*/
public
function
setBlackSmoke
(
int
$blackSmoke
)
:
void
{
$this
->
blackSmoke
=
$blackSmoke
;
}
/**
* @return int
*/
public
function
getDeviceState
()
:
int
{
return
$this
->
deviceState
;
}
/**
* @param int $deviceState
*/
public
function
setDeviceState
(
int
$deviceState
)
:
void
{
$this
->
deviceState
=
$deviceState
;
}
/**
* @return mixed
*/
public
function
getBoxId
()
{
return
$this
->
boxId
;
}
/**
* @param mixed $boxId
*/
public
function
setBoxId
(
$boxId
)
:
void
{
$this
->
boxId
=
$boxId
;
}
/**
* @return int
*/
public
function
getAcRetain
()
:
int
{
return
$this
->
acRetain
;
}
/**
* @param int $acRetain
*/
public
function
setAcRetain
(
int
$acRetain
)
:
void
{
$this
->
acRetain
=
$acRetain
;
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment