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

Commit

Permalink
Name changes
Browse files Browse the repository at this point in the history
  • Loading branch information
fiz committed Feb 24, 2018
1 parent 7f833d4 commit 4fd14c1
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 18 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Adapter for use with ESP8266 wifi devices and Mozilla-IOT gateway from https://github.com/mozilla-iot. Based on code from the http-on-off-adapter (https://github.com/mozilla-iot/http-on-off-adapter).
Adapter for use with devices such as the ESP8266, Arduino, laptops, etc and the Mozilla-IOT gateway from https://github.com/mozilla-iot. Based on code from the http-on-off-adapter (https://github.com/mozilla-iot/http-on-off-adapter).

This adapter scans a range of IP addresses defined in package.json for ESP8266/nodeMCU/Arduino/laptops/desktops/etc that respond with json data defining an IOT device. An ESP8266/Arduino example sketch is included. The name, id and description returned in the json data should be unique for each device.
When the adapter pairing is performed ("+" button on main page), this adapter scans a range of IP addresses defined in package.json for ESP8266/nodeMCU/Arduino/laptops/desktops/etc that respond with json data defining an IOT device. An ESP8266/Arduino example sketch and PHP code is included. The name, id and description returned in the json data should be unique for each device.

To use:
Put files in the "gateway/src/addons/espThing" folder.
Edit the range of IP addresses in package.json.
Power up all the ESP8266 devices.
Power up all the ESP devices.
Start the gateway.
Login to the gateway (ex https://localhost:4443).
Enable the adapter by clicking the "3 bars" in the top/left corner of the web browser.
Expand Down
2 changes: 1 addition & 1 deletion SHA256SUMS
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
0b63bdc278620212232e368f033b1edbc6200fa0d583d48c7c8db759695d32a9 package.json
7095153ef103177f276e0c4367560b0e5a34fd8d2d93dd6cae317798d62607ec index.js
fa53a511f6ca9c09ce99e731fff882bd2166a51ed1b5326aea13278216b823ac ./esp8266-adapter.js
fa53a511f6ca9c09ce99e731fff882bd2166a51ed1b5326aea13278216b823ac ./esp-adapter.js
1f256ecad192880510e84ad60474eab7589218784b9a50bc7ceee34c2b91f1d5 LICENSE
25 changes: 13 additions & 12 deletions espThing/espThing.ino
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ void setup() {
digitalWrite(LED_BUILTIN, LOW);

Serial.begin(115200);
WiFi.begin("Network name", "Password"); //Connect to the WiFi network
WiFi.begin("{ssid}", "{passcode}"); //Connect to the WiFi network

while (WiFi.status() != WL_CONNECTED) { //Wait for connection
delay(500);
Expand All @@ -23,6 +23,10 @@ void setup() {
//Define the handling function for the config response
server.on("/thing", []() {
String configThing = "{\
\"name\": \"ESP8266\",\
\"type\": \"thing\",\
\"id\": \"ESP8266-01\",\
\"description\": \"myESP8266\",\
\"properties\": {\
\"Clock\": {\
\"type\": \"number\",\
Expand All @@ -37,31 +41,29 @@ void setup() {
}\
}\
}";

server.send(200, "text/plain", configThing);
server.send(200, "text/json", configThing);
});

// respond to setting LED on/off
// attempts to set clock simply return current clock value
server.on("/thing/set", []() { //Define the handling function for the config response
char respondThing[512];
sprintf(respondThing, "{}");
server.on("/thing/set", []() { //Define the handling function for the config response
char respondThing[2048];

if(server.arg("led")!= "") {
if(server.arg("led")=="true" ) {
digitalWrite(LED_BUILTIN, HIGH);
} else {
digitalWrite(LED_BUILTIN, LOW);
}
unsigned long currentMillis = millis();
sprintf(respondThing, "{\"Clock\": %d}", currentMillis);
sprintf(respondThing, "%s{\"Clock\": %d}", hdr.c_str(), currentMillis);
}

if(server.arg("Clock")!= "") {
unsigned long currentMillis = millis();
sprintf(respondThing, "{\"Clock\": %d}", currentMillis);
sprintf(respondThing, "%s{\"Clock\": %d}", hdr.c_str(), currentMillis);
}

server.send(200, "text/plain", respondThing);
server.send(200, "text/json", respondThing);
});

server.begin(); //Start the server
Expand All @@ -73,5 +75,4 @@ void loop() {

server.handleClient(); //Handling of incoming requests

}

}
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* index.js - Loads the ESP8266 adapter.
* index.js - Loads the ESP adapter.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ESPadapter",
"version": "0.1.0",
"version": "0.3.0",
"description": "ESP Mozillia-IOT adapter",
"main": "index.js",
"keywords": [
Expand Down

0 comments on commit 4fd14c1

Please sign in to comment.