Skip to content
This repository was archived by the owner on Apr 13, 2018. It is now read-only.

Commit

Permalink
Changes to support multiple Things per IP Address
Browse files Browse the repository at this point in the history
  • Loading branch information
willif committed Mar 2, 2018
1 parent f204d21 commit 1fcd7b7
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 8 deletions.
6 changes: 3 additions & 3 deletions SHA256SUMS
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
561eb97660ba2cb014c78f5f9bc2fc29dc70d9d2edfca169a7f16cdfbaf09b5f package.json
eaa7939383e1c494de10b5d6f773891390db1050db38e1ca340b50536b5697fb package.json
78bb6db8d82d3251f99a0bf0e9f20211757062bffc8f4b9559f4ff396ca98b3c esp-adapter.js
f247f379a9bcd86d7246582dac7246284fb8f5763088037004a7274afca475c0 index.js
1f256ecad192880510e84ad60474eab7589218784b9a50bc7ceee34c2b91f1d5 LICENSE
8d744f4611a9717879d78ba96567bab53b9a03c08c70c7b222cc52dca5291964 espThing.ino
174f9b60c85246da88e1ffe30c1f80cda607cef47b2e8840064a69f7e2215e6c phpThing.tgz
c85b97b25b4f61dfa61500da1ff0e95e0db5ff5d317188c69e5c2d106bce0fb1 espThing.ino
cc2330c89e31ad55eb66787990e3aaa8c33c3592f19c096f8a10f0e6e096b9fe phpThings.tgz
32 changes: 29 additions & 3 deletions espThing.ino
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ void setup() {
Serial.println("Getting thing");
String configThing = "[\
{\
\"name\": \"ESP8266\",\
\"name\": \"ESP8266 Thing 1\",\
\"type\": \"thing\",\
\"description\": \"myESP8266\",\
\"properties\": {\
\"clock\": {\
\"type\": \"number\",\
\"unit\": \"Ticks\",\
\"description\": \"The millisec clock count\",\
\"description\": \"The short millisec clock count\",\
\"href\":\"/properties/clock\"\
},\
\"led\": {\
Expand All @@ -49,7 +49,20 @@ void setup() {
\"href\":\"/properties/led\"\
}\
}\
},\
{\
\"name\": \"ESP8266 Thing 2\",\
\"type\": \"thing\",\
\"description\": \"myESP8266\",\
\"properties\": {\
\"anotherclock\": {\
\"type\": \"number\",\
\"unit\": \"Ticks\",\
\"description\": \"The long millisec clock count\",\
\"href\":\"/properties/anotherclock\"\
}\
}\
}\
]";
server.send(200, "text/json", configThing);
});
Expand Down Expand Up @@ -88,9 +101,22 @@ void setup() {
if(!server.authenticate(thingUser, thingPwd))
return server.requestAuthentication();

char respondThing[1024];
// clock can only be read, not set
// truncate to 8 bits as an example
sprintf(respondThing, "{\"clock\":\"%d\"}", millis()&0xff);
server.send(200, "text/json", respondThing);
});

// respond to clock property
server.on("/things/esp/properties/anotherclock", []() {
Serial.println("led thing property");
if(!server.authenticate(thingUser, thingPwd))
return server.requestAuthentication();

char respondThing[1024];
// clock can only be read, not set
sprintf(respondThing, "{\"clock\":\"%d\"}", millis());
sprintf(respondThing, "{\"anotherclock\":\"%d\"}", millis());
server.send(200, "text/json", respondThing);
});

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"SHA256SUMS",
"esp-adapter.js",
"index.js",
"phpThing.tgz",
"phpThings.tgz",
"espThing.ino"
],
"moziot": {
Expand Down
2 changes: 1 addition & 1 deletion package.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

rm -f SHA256SUMS
sha256sum -- package.json *.js LICENSE espThing.ino phpThing.tgz > SHA256SUMS
sha256sum -- package.json *.js LICENSE espThing.ino phpThings.tgz > SHA256SUMS
npm pack

Binary file removed phpThing.tgz
Binary file not shown.

0 comments on commit 1fcd7b7

Please sign in to comment.