diff --git a/CMakeLists.txt b/CMakeLists.txt index 612e811d..3b6c17a1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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/ ) diff --git a/firmware/board/raspberrypi/ovl/etc/fstab b/firmware/board/raspberrypi/ovl/etc/fstab index fae68968..76424f46 100644 --- a/firmware/board/raspberrypi/ovl/etc/fstab +++ b/firmware/board/raspberrypi/ovl/etc/fstab @@ -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 diff --git a/src/chacond/src/Chacon.c b/src/chacond/src/Chacon.c index 86bd7815..cbb3e2f9 100644 --- a/src/chacond/src/Chacon.c +++ b/src/chacond/src/Chacon.c @@ -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) diff --git a/src/data/Devices.json b/src/data/Devices.json new file mode 100644 index 00000000..7532af4a --- /dev/null +++ b/src/data/Devices.json @@ -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 + } + ] + } +} diff --git a/src/data/capabilities.json b/src/data/capabilities.json new file mode 100644 index 00000000..a3afdb7b --- /dev/null +++ b/src/data/capabilities.json @@ -0,0 +1,7 @@ +{ + "capabilities":[ + "lights", + "shutters", + "sprinklers" + ] +} diff --git a/src/domod/src/main.cpp b/src/domod/src/main.cpp index 27247521..6f5689a9 100644 --- a/src/domod/src/main.cpp +++ b/src/domod/src/main.cpp @@ -53,13 +53,13 @@ extern "C" { static struct ubus_context *setupUbus (void) { ubus_context *theCtx; - + if (uloop_init () !=0) { - + fprintf (stderr, "Failed to init Uloop.\n"); return NULL; } - + signal (SIGPIPE, SIG_IGN); theCtx = ubus_connect (NULL); @@ -71,7 +71,7 @@ static struct ubus_context *setupUbus (void) } ubus_add_uloop (theCtx); - + return theCtx; } } // SetupUbus. @@ -91,11 +91,11 @@ int main (void) thePath = getenv ("DOMO_WRITE_PATH"); thePath += "/Devices.json"; - + //printf ("DOMO PATH: %s\n", thePath.c_str()); - + Devices theDevices (thePath); - + if (theDevices.Setup() != 0) { return -1; diff --git a/src/domod/src/ubus/capabilities_lights.cpp b/src/domod/src/ubus/capabilities_lights.cpp index 0e7da773..e5ad3936 100644 --- a/src/domod/src/ubus/capabilities_lights.cpp +++ b/src/domod/src/ubus/capabilities_lights.cpp @@ -138,8 +138,9 @@ int CapabilitiesLights::Post (struct ubus_context *aCtx, struct ubus_request_dat Json::Value theOutput; Json::Value theElement; int theID; - bool theState; - + bool theState; + fprintf (stderr,"CapabilitiesLights::Post \n"); + if (!theReader.parse (theString, theRoot)) { fprintf (stderr, "Failed parse the parameters.\n"); diff --git a/src/domod/src/ubus/capabilities_sprinklers.cpp b/src/domod/src/ubus/capabilities_sprinklers.cpp index 24a6d59d..65b74a5e 100644 --- a/src/domod/src/ubus/capabilities_sprinklers.cpp +++ b/src/domod/src/ubus/capabilities_sprinklers.cpp @@ -29,6 +29,8 @@ extern "C" { #include } +#include + #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); +} diff --git a/src/domod/src/ubus/capabilities_sprinklers.h b/src/domod/src/ubus/capabilities_sprinklers.h index e399cb35..6d4a9e0d 100644 --- a/src/domod/src/ubus/capabilities_sprinklers.h +++ b/src/domod/src/ubus/capabilities_sprinklers.h @@ -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; }; diff --git a/src/restd/src/main.cpp b/src/restd/src/main.cpp index 0b237f2e..85a36535 100644 --- a/src/restd/src/main.cpp +++ b/src/restd/src/main.cpp @@ -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}; diff --git a/src/sprinklersd/src/UbusSprinklerModel.cpp b/src/sprinklersd/src/UbusSprinklerModel.cpp index a6b00a81..59b67866 100644 --- a/src/sprinklersd/src/UbusSprinklerModel.cpp +++ b/src/sprinklersd/src/UbusSprinklerModel.cpp @@ -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") { } diff --git a/src/sprinklersd/src/sprinklers.cpp b/src/sprinklersd/src/sprinklers.cpp index 356de25d..ba022316 100644 --- a/src/sprinklersd/src/sprinklers.cpp +++ b/src/sprinklersd/src/sprinklers.cpp @@ -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); diff --git a/src/ui/Domo/src/components/Lights.vue b/src/ui/Domo/src/components/Lights.vue index aa0dc077..a9fbcd74 100644 --- a/src/ui/Domo/src/components/Lights.vue +++ b/src/ui/Domo/src/components/Lights.vue @@ -1,14 +1,14 @@ diff --git a/src/ui/Domo/src/components/Light.vue b/src/ui/Domo/src/components/cell-switch.vue similarity index 100% rename from src/ui/Domo/src/components/Light.vue rename to src/ui/Domo/src/components/cell-switch.vue