Functional sprinkler screen.
This commit is contained in:
@@ -20,12 +20,14 @@ add_custom_target (deploy
|
||||
COMMAND mkdir -p ${CMAKE_SOURCE_DIR}/build/install
|
||||
COMMAND mkdir -p ${CMAKE_SOURCE_DIR}/build/install/bin/
|
||||
COMMAND mkdir -p ${CMAKE_SOURCE_DIR}/build/install/lib/
|
||||
COMMAND mkdir -p ${CMAKE_SOURCE_DIR}/build/install/rsc/
|
||||
|
||||
#COMMAND cp ${CMAKE_SOURCE_DIR}/scripts/Domo.sh ${CMAKE_SOURCE_DIR}/build/install
|
||||
COMMAND cp ${CMAKE_SOURCE_DIR}/build/bin/* ${CMAKE_SOURCE_DIR}/build/install/bin/
|
||||
COMMAND cp ${CMAKE_SOURCE_DIR}/build/lib/*.so ${CMAKE_SOURCE_DIR}/build/install/lib/
|
||||
#COMMAND cp -a ${CMAKE_SOURCE_DIR}/build/html ${CMAKE_SOURCE_DIR}/build/install/
|
||||
#COMMAND cp -a ${CMAKE_SOURCE_DIR}/build/rsc ${CMAKE_SOURCE_DIR}/build/install/
|
||||
COMMAND cp -a ${CMAKE_SOURCE_DIR}/build/html ${CMAKE_SOURCE_DIR}/build/install/
|
||||
|
||||
COMMAND rsync -av --delete ${CMAKE_SOURCE_DIR}/build/install/* root@${PI}:/opt/Domo/
|
||||
|
||||
COMMAND rsync -av --delete ${CMAKE_SOURCE_DIR}/src/data/* root@${PI}:/home/rpi/domo/
|
||||
)
|
||||
|
||||
@@ -6,4 +6,4 @@ tmpfs /dev/shm tmpfs mode=0777 0 0
|
||||
tmpfs /tmp tmpfs mode=1777 0 0
|
||||
tmpfs /run tmpfs mode=0755,nosuid,nodev 0 0
|
||||
sysfs /sys sysfs defaults 0 0
|
||||
/dev/mmcblk0p3 /home/rpi vfat defaults,uid=1000,gid=1000 0 0
|
||||
/dev/mmcblk0p3 /home/rpi vfat defaults,rw,uid=1000,gid=1000 0 0
|
||||
|
||||
@@ -87,7 +87,7 @@ int Chacon_SetInterruptorState (uint32_t aSender, uint32_t anInterruptor, bool a
|
||||
itobInterruptor (anInterruptor, 4);
|
||||
|
||||
/* Send the State Five Time. */
|
||||
for (i = 0; i < 5; i++) {
|
||||
for (i = 0; i < 10; i++) {
|
||||
|
||||
transmit (aState);
|
||||
delay (10); // attendre 10 ms (sinon le socket nous ignore)
|
||||
|
||||
74
src/data/Devices.json
Normal file
74
src/data/Devices.json
Normal file
@@ -0,0 +1,74 @@
|
||||
{
|
||||
"Lights" : {
|
||||
"speach_name": "lumière",
|
||||
"data": [
|
||||
{
|
||||
"id": 1,
|
||||
"name": "Bureau JB",
|
||||
"speach_name": "bureau",
|
||||
"zone": "",
|
||||
"state": true,
|
||||
"sender": 12797322,
|
||||
"interruptor": 0
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"name": "Salon",
|
||||
"speach_name": "salon",
|
||||
"zone": "",
|
||||
"state": false,
|
||||
"sender": 12797322,
|
||||
"interruptor": 1
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"name": "Sapin",
|
||||
"speach_name": "sapin",
|
||||
"zone": "",
|
||||
"state": false,
|
||||
"sender": 12797322,
|
||||
"interruptor": 2
|
||||
}
|
||||
]
|
||||
},
|
||||
"Shutters" : {
|
||||
"speach_name": "volet",
|
||||
"data": [
|
||||
{
|
||||
"id": 1,
|
||||
"name": "Chambre de JB",
|
||||
"zone": "",
|
||||
"state": true,
|
||||
"sender": 14997046,
|
||||
"interruptor": 12,
|
||||
"speed_up": 20,
|
||||
"speed_down": 18
|
||||
}
|
||||
]
|
||||
},
|
||||
"Sprinklers" : {
|
||||
"speach_name": "station",
|
||||
"data": [
|
||||
{
|
||||
"id": 7,
|
||||
"name": "Zone A",
|
||||
"state": false
|
||||
},
|
||||
{
|
||||
"id": 8,
|
||||
"name": "Zone B",
|
||||
"state": false
|
||||
},
|
||||
{
|
||||
"id": 25,
|
||||
"name": "Zone C",
|
||||
"state": false
|
||||
},
|
||||
{
|
||||
"id": 24,
|
||||
"name": "Zone D",
|
||||
"state": false
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
7
src/data/capabilities.json
Normal file
7
src/data/capabilities.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"capabilities":[
|
||||
"lights",
|
||||
"shutters",
|
||||
"sprinklers"
|
||||
]
|
||||
}
|
||||
@@ -139,6 +139,7 @@ int CapabilitiesLights::Post (struct ubus_context *aCtx, struct ubus_request_dat
|
||||
Json::Value theElement;
|
||||
int theID;
|
||||
bool theState;
|
||||
fprintf (stderr,"CapabilitiesLights::Post \n");
|
||||
|
||||
if (!theReader.parse (theString, theRoot)) {
|
||||
|
||||
|
||||
@@ -29,6 +29,8 @@ extern "C" {
|
||||
#include <libubox/blobmsg_json.h>
|
||||
}
|
||||
|
||||
#include <ubuscpp/UBusCall.h>
|
||||
|
||||
#include "models/Devices.h"
|
||||
|
||||
#include "capabilities_sprinklers.h"
|
||||
@@ -83,7 +85,7 @@ int CapabilitiesSprinklers::Get (struct ubus_context *aCtx, struct ubus_request_
|
||||
|
||||
blob_buf_init (&theBuf, 0);
|
||||
|
||||
blobmsg_add_json_from_string (&theBuf, mDevices->get("Sprinkers").c_str());
|
||||
blobmsg_add_json_from_string (&theBuf, mDevices->get("Sprinklers").c_str());
|
||||
|
||||
theResult = ubus_send_reply (aCtx, aReq, theBuf.head);
|
||||
|
||||
@@ -124,9 +126,66 @@ int CapabilitiesSprinklers::Put (struct ubus_context*, struct ubus_request_data*
|
||||
*
|
||||
* @brief Get the List of the Capabilities.
|
||||
*/
|
||||
int CapabilitiesSprinklers::Post (struct ubus_context*, struct ubus_request_data*, struct blob_attr*)
|
||||
int CapabilitiesSprinklers::Post (struct ubus_context *aCtx, struct ubus_request_data *aReq,
|
||||
struct blob_attr *aMsg)
|
||||
{
|
||||
int theResult = 0;
|
||||
int theResult;
|
||||
struct blob_buf theBuf = {0};
|
||||
char *theString = blobmsg_format_json (aMsg, true);
|
||||
Json::Reader theReader;
|
||||
Json::StyledWriter theWriter;
|
||||
Json::Value theRoot;
|
||||
Json::Value theOutput;
|
||||
Json::Value theElement;
|
||||
int theID;
|
||||
bool theState;
|
||||
fprintf (stderr,"CapabilitiesSprinklers::Post \n");
|
||||
|
||||
if (!theReader.parse (theString, theRoot)) {
|
||||
|
||||
fprintf (stderr, "Failed parse the parameters.\n");
|
||||
return UBUS_STATUS_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
theID = theRoot["id"].asInt();
|
||||
theState = theRoot["state"].asBool();
|
||||
|
||||
theElement = mDevices->get("Sprinklers", theID);
|
||||
theElement["state"] = theState;
|
||||
|
||||
if (ChangeState(theElement) == 0) {
|
||||
|
||||
mDevices->set ("Sprinklers", theID, theElement);
|
||||
}
|
||||
|
||||
theOutput["Sprinklers"] = theElement;
|
||||
|
||||
blob_buf_init (&theBuf, 0);
|
||||
|
||||
blobmsg_add_json_from_string (&theBuf, theWriter.write(theOutput).c_str());
|
||||
|
||||
theResult = ubus_send_reply (aCtx, aReq, theBuf.head);
|
||||
|
||||
blob_buf_free (&theBuf);
|
||||
|
||||
return theResult;
|
||||
}
|
||||
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn ChangeState
|
||||
*
|
||||
* @brief Change the State of an station.
|
||||
*/
|
||||
int CapabilitiesSprinklers::ChangeState (const Json::Value &aStation)
|
||||
{
|
||||
UBusCall theCmd;
|
||||
Json::Value theParam;
|
||||
Json::StyledWriter theWriter;
|
||||
std::string theResult;
|
||||
|
||||
theParam["station"] = aStation["id"];
|
||||
theParam["state"] = aStation["state"];
|
||||
|
||||
return theCmd.Exec ("sprinklers", "set", theWriter.write(theParam).c_str(),theResult);
|
||||
}
|
||||
|
||||
@@ -50,6 +50,7 @@ public:
|
||||
int Post (struct ubus_context*, struct ubus_request_data*, struct blob_attr*);
|
||||
|
||||
private:
|
||||
int ChangeState (const Json::Value &aStation);
|
||||
Devices *mDevices;
|
||||
};
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ pthread_rwlock_t gRwlock = PTHREAD_RWLOCK_INITIALIZER;
|
||||
int main (void)
|
||||
{
|
||||
const char *theOptions[] = {
|
||||
"document_root", "html",
|
||||
"document_root", "/opt/Domo/html",
|
||||
"listening_ports", "8081",
|
||||
0};
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ static ObjectType gSprinklerModelUbus_types(
|
||||
* @brief Constructor of the UBus Mixer Volume.
|
||||
*/
|
||||
SprinkerModel::SprinkerModel (void) :
|
||||
UBusObject (gSprinklerModelUbus_types, "sprinkers")
|
||||
UBusObject (gSprinklerModelUbus_types, "sprinklers")
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ int sprinklers_setup (void)
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (const Json::Value& theElement : theRoot["Sprinkers"]) {
|
||||
for (const Json::Value& theElement : theRoot["Sprinklers"]) {
|
||||
|
||||
theIDVal = theElement["id"].asInt();
|
||||
sprinkler_setup_station (theIDVal);
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
<template>
|
||||
<h1>Lights</h1>
|
||||
<group>
|
||||
<light v-for="item in lights" :data="item" @on-change="setLight"></light>
|
||||
<cell-switch v-for="item in lights" :data="item" @on-change="setLight"></cell-switch>
|
||||
</group>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import Group from 'vux/components/group'
|
||||
import Cell from 'vux/components/cell'
|
||||
import Light from './Light'
|
||||
import CellSwitch from './cell-switch'
|
||||
|
||||
export default {
|
||||
// Data
|
||||
@@ -26,7 +26,7 @@ export default {
|
||||
components: {
|
||||
Group,
|
||||
Cell,
|
||||
Light
|
||||
CellSwitch
|
||||
},
|
||||
methods: {
|
||||
/* Get Lights */
|
||||
|
||||
@@ -1,6 +1,59 @@
|
||||
<template>
|
||||
<h1>Sprinklers</h1>
|
||||
<group>
|
||||
<cell-switch v-for="item in sprinklers" :data="item" @on-change="setSprinkler">
|
||||
</cell-switch>
|
||||
</group>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import Group from 'vux/components/group'
|
||||
import Cell from 'vux/components/cell'
|
||||
import CellSwitch from './cell-switch'
|
||||
|
||||
export default {
|
||||
// Data
|
||||
data () {
|
||||
// console.log('Data init.');
|
||||
return {
|
||||
sprinklers: []
|
||||
}
|
||||
},
|
||||
ready () {
|
||||
console.log('Get Sprinklers state')
|
||||
this.getSprinklers()
|
||||
},
|
||||
// Components used.
|
||||
components: {
|
||||
Group,
|
||||
Cell,
|
||||
CellSwitch
|
||||
},
|
||||
methods: {
|
||||
/* Get Sprinklers */
|
||||
getSprinklers () {
|
||||
this.$http.get('http://192.168.1.6:8081/v1/capabilities/sprinklers')
|
||||
.then(function (response) {
|
||||
this.$set('sprinklers', response.data.Sprinklers)
|
||||
console.log('Success!:', response.data)
|
||||
}, function (err) {
|
||||
console.log(err)
|
||||
})
|
||||
},
|
||||
/* Set Sprinkler */
|
||||
setSprinkler (data) {
|
||||
var msg = ''
|
||||
console.log(data)
|
||||
msg = '{"id": ' + data.id + ', "state": ' + data.state + '}'
|
||||
console.log(msg)
|
||||
this.$http.post('http://192.168.1.6:8081/v1/capabilities/sprinklers', msg)
|
||||
.then(function (response) {
|
||||
console.log('Success!:', response.data)
|
||||
}, function (err) {
|
||||
console.log(err)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user