Functional sprinkler screen.

This commit is contained in:
2016-05-16 23:29:04 +02:00
parent 08e7f73f44
commit 0a12c35f70
15 changed files with 219 additions and 22 deletions

View File

@@ -20,12 +20,14 @@ add_custom_target (deploy
COMMAND mkdir -p ${CMAKE_SOURCE_DIR}/build/install 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/bin/
COMMAND mkdir -p ${CMAKE_SOURCE_DIR}/build/install/lib/ 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}/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/bin/* ${CMAKE_SOURCE_DIR}/build/install/bin/
COMMAND cp ${CMAKE_SOURCE_DIR}/build/lib/*.so ${CMAKE_SOURCE_DIR}/build/install/lib/ 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/html ${CMAKE_SOURCE_DIR}/build/install/
#COMMAND cp -a ${CMAKE_SOURCE_DIR}/build/rsc ${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}/build/install/* root@${PI}:/opt/Domo/
COMMAND rsync -av --delete ${CMAKE_SOURCE_DIR}/src/data/* root@${PI}:/home/rpi/domo/
) )

View File

@@ -6,4 +6,4 @@ tmpfs /dev/shm tmpfs mode=0777 0 0
tmpfs /tmp tmpfs mode=1777 0 0 tmpfs /tmp tmpfs mode=1777 0 0
tmpfs /run tmpfs mode=0755,nosuid,nodev 0 0 tmpfs /run tmpfs mode=0755,nosuid,nodev 0 0
sysfs /sys sysfs defaults 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

View File

@@ -87,7 +87,7 @@ int Chacon_SetInterruptorState (uint32_t aSender, uint32_t anInterruptor, bool a
itobInterruptor (anInterruptor, 4); itobInterruptor (anInterruptor, 4);
/* Send the State Five Time. */ /* Send the State Five Time. */
for (i = 0; i < 5; i++) { for (i = 0; i < 10; i++) {
transmit (aState); transmit (aState);
delay (10); // attendre 10 ms (sinon le socket nous ignore) delay (10); // attendre 10 ms (sinon le socket nous ignore)

74
src/data/Devices.json Normal file
View 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
}
]
}
}

View File

@@ -0,0 +1,7 @@
{
"capabilities":[
"lights",
"shutters",
"sprinklers"
]
}

View File

@@ -53,13 +53,13 @@ extern "C" {
static struct ubus_context *setupUbus (void) static struct ubus_context *setupUbus (void)
{ {
ubus_context *theCtx; ubus_context *theCtx;
if (uloop_init () !=0) { if (uloop_init () !=0) {
fprintf (stderr, "Failed to init Uloop.\n"); fprintf (stderr, "Failed to init Uloop.\n");
return NULL; return NULL;
} }
signal (SIGPIPE, SIG_IGN); signal (SIGPIPE, SIG_IGN);
theCtx = ubus_connect (NULL); theCtx = ubus_connect (NULL);
@@ -71,7 +71,7 @@ static struct ubus_context *setupUbus (void)
} }
ubus_add_uloop (theCtx); ubus_add_uloop (theCtx);
return theCtx; return theCtx;
} }
} // SetupUbus. } // SetupUbus.
@@ -91,11 +91,11 @@ int main (void)
thePath = getenv ("DOMO_WRITE_PATH"); thePath = getenv ("DOMO_WRITE_PATH");
thePath += "/Devices.json"; thePath += "/Devices.json";
//printf ("DOMO PATH: %s\n", thePath.c_str()); //printf ("DOMO PATH: %s\n", thePath.c_str());
Devices theDevices (thePath); Devices theDevices (thePath);
if (theDevices.Setup() != 0) { if (theDevices.Setup() != 0) {
return -1; return -1;

View File

@@ -138,8 +138,9 @@ int CapabilitiesLights::Post (struct ubus_context *aCtx, struct ubus_request_dat
Json::Value theOutput; Json::Value theOutput;
Json::Value theElement; Json::Value theElement;
int theID; int theID;
bool theState; bool theState;
fprintf (stderr,"CapabilitiesLights::Post \n");
if (!theReader.parse (theString, theRoot)) { if (!theReader.parse (theString, theRoot)) {
fprintf (stderr, "Failed parse the parameters.\n"); fprintf (stderr, "Failed parse the parameters.\n");

View File

@@ -29,6 +29,8 @@ extern "C" {
#include <libubox/blobmsg_json.h> #include <libubox/blobmsg_json.h>
} }
#include <ubuscpp/UBusCall.h>
#include "models/Devices.h" #include "models/Devices.h"
#include "capabilities_sprinklers.h" #include "capabilities_sprinklers.h"
@@ -83,7 +85,7 @@ int CapabilitiesSprinklers::Get (struct ubus_context *aCtx, struct ubus_request_
blob_buf_init (&theBuf, 0); 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); 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. * @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; 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);
}

View File

@@ -50,6 +50,7 @@ public:
int Post (struct ubus_context*, struct ubus_request_data*, struct blob_attr*); int Post (struct ubus_context*, struct ubus_request_data*, struct blob_attr*);
private: private:
int ChangeState (const Json::Value &aStation);
Devices *mDevices; Devices *mDevices;
}; };

View File

@@ -54,7 +54,7 @@ pthread_rwlock_t gRwlock = PTHREAD_RWLOCK_INITIALIZER;
int main (void) int main (void)
{ {
const char *theOptions[] = { const char *theOptions[] = {
"document_root", "html", "document_root", "/opt/Domo/html",
"listening_ports", "8081", "listening_ports", "8081",
0}; 0};

View File

@@ -58,7 +58,7 @@ static ObjectType gSprinklerModelUbus_types(
* @brief Constructor of the UBus Mixer Volume. * @brief Constructor of the UBus Mixer Volume.
*/ */
SprinkerModel::SprinkerModel (void) : SprinkerModel::SprinkerModel (void) :
UBusObject (gSprinklerModelUbus_types, "sprinkers") UBusObject (gSprinklerModelUbus_types, "sprinklers")
{ {
} }

View File

@@ -65,7 +65,7 @@ int sprinklers_setup (void)
return -1; return -1;
} }
for (const Json::Value& theElement : theRoot["Sprinkers"]) { for (const Json::Value& theElement : theRoot["Sprinklers"]) {
theIDVal = theElement["id"].asInt(); theIDVal = theElement["id"].asInt();
sprinkler_setup_station (theIDVal); sprinkler_setup_station (theIDVal);

View File

@@ -1,14 +1,14 @@
<template> <template>
<h1>Lights</h1> <h1>Lights</h1>
<group> <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> </group>
</template> </template>
<script> <script>
import Group from 'vux/components/group' import Group from 'vux/components/group'
import Cell from 'vux/components/cell' import Cell from 'vux/components/cell'
import Light from './Light' import CellSwitch from './cell-switch'
export default { export default {
// Data // Data
@@ -26,7 +26,7 @@ export default {
components: { components: {
Group, Group,
Cell, Cell,
Light CellSwitch
}, },
methods: { methods: {
/* Get Lights */ /* Get Lights */

View File

@@ -1,6 +1,59 @@
<template> <template>
<h1>Sprinklers</h1> <h1>Sprinklers</h1>
<group>
<cell-switch v-for="item in sprinklers" :data="item" @on-change="setSprinkler">
</cell-switch>
</group>
</template> </template>
<script> <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> </script>