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

Commit

Permalink
Merge branch 'master' of https://github.com/fiz1962/ESP-adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
fiz committed Mar 4, 2018
2 parents d1a0392 + 007cdab commit 3021ed8
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 19 deletions.
8 changes: 4 additions & 4 deletions SHA256SUMS
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
561eb97660ba2cb014c78f5f9bc2fc29dc70d9d2edfca169a7f16cdfbaf09b5f package.json
78bb6db8d82d3251f99a0bf0e9f20211757062bffc8f4b9559f4ff396ca98b3c esp-adapter.js
76b11def253ba876ec916183a3a410640dcc88025c6c48219a1fb08abe8f491a package.json
99c67377e5a4a401a0e6e401b58547a255e8dbfd8f24fec72489cc28a0501018 esp-adapter.js
f247f379a9bcd86d7246582dac7246284fb8f5763088037004a7274afca475c0 index.js
1f256ecad192880510e84ad60474eab7589218784b9a50bc7ceee34c2b91f1d5 LICENSE
8d744f4611a9717879d78ba96567bab53b9a03c08c70c7b222cc52dca5291964 espThing.ino
174f9b60c85246da88e1ffe30c1f80cda607cef47b2e8840064a69f7e2215e6c phpThing.tgz
c85b97b25b4f61dfa61500da1ff0e95e0db5ff5d317188c69e5c2d106bce0fb1 espThing.ino
cc2330c89e31ad55eb66787990e3aaa8c33c3592f19c096f8a10f0e6e096b9fe phpThings.tgz
19 changes: 16 additions & 3 deletions esp-adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,24 @@

'use strict';

const Adapter = require('../adapter');
const Device = require('../device');
const Property = require('../property');
const fetch = require('node-fetch');

let Adapter, Device, Property;
try {
Adapter = require('../adapter');
Device = require('../device');
Property = require('../property');
} catch (e) {
if (e.code !== 'MODULE_NOT_FOUND') {
throw e;
}

const gwa = require('gateway-addon');
Adapter = gwa.Adapter;
Device = gwa.Device;
Property = gwa.Property;
}

class ESPProperty extends Property {
constructor(device, name, propertyDescription) {
super(device, name, propertyDescription);
Expand Down
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
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ESP-adapter",
"version": "0.4.0",
"version": "0.4.1",
"description": "ESP Mozillia-IOT adapter",
"main": "index.js",
"keywords": [
Expand All @@ -25,13 +25,13 @@
"SHA256SUMS",
"esp-adapter.js",
"index.js",
"phpThing.tgz",
"phpThings.tgz",
"espThing.ino"
],
"moziot": {
"api": {
"min": 1,
"max": 1
"max": 2
},
"plugin": true,
"exec": "{nodeLoader} {path}",
Expand Down
6 changes: 0 additions & 6 deletions package.sh

This file was deleted.

Binary file removed phpThing.tgz
Binary file not shown.

0 comments on commit 3021ed8

Please sign in to comment.