Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit 4ea31a72ab706e77df8562db834f0d252e15f10a @marvinroger committed Dec 13, 2015
Showing with 5,786 additions and 0 deletions.
  1. +21 −0 LICENSE
  2. +162 −0 README.md
  3. +29 −0 examples/SimpleActuator/SimpleActuator.ino
  4. +35 −0 examples/SimpleSensor/SimpleSensor.ino
  5. +28 −0 keywords.txt
  6. +9 −0 library.properties
  7. +10 −0 src/3rd/ArduinoJson/LICENSE.md
  8. +12 −0 src/3rd/ArduinoJson/include/ArduinoJson.h
  9. +32 −0 src/3rd/ArduinoJson/include/ArduinoJson/Arduino/Print.hpp
  10. +18 −0 src/3rd/ArduinoJson/include/ArduinoJson/Arduino/String.hpp
  11. +17 −0 src/3rd/ArduinoJson/include/ArduinoJson/DynamicJsonBuffer.hpp
  12. +93 −0 src/3rd/ArduinoJson/include/ArduinoJson/Internals/BlockJsonBuffer.hpp
  13. +13 −0 src/3rd/ArduinoJson/include/ArduinoJson/Internals/Comments.hpp
  14. +20 −0 src/3rd/ArduinoJson/include/ArduinoJson/Internals/DummyPrint.hpp
  15. +32 −0 src/3rd/ArduinoJson/include/ArduinoJson/Internals/DynamicStringBuilder.hpp
  16. +39 −0 src/3rd/ArduinoJson/include/ArduinoJson/Internals/Encoding.hpp
  17. +13 −0 src/3rd/ArduinoJson/include/ArduinoJson/Internals/ForceInline.hpp
  18. +54 −0 src/3rd/ArduinoJson/include/ArduinoJson/Internals/IndentedPrint.hpp
  19. +24 −0 src/3rd/ArduinoJson/include/ArduinoJson/Internals/JsonBufferAllocated.hpp
  20. +20 −0 src/3rd/ArduinoJson/include/ArduinoJson/Internals/JsonFloat.hpp
  21. +13 −0 src/3rd/ArduinoJson/include/ArduinoJson/Internals/JsonInteger.hpp
  22. +46 −0 src/3rd/ArduinoJson/include/ArduinoJson/Internals/JsonParser.hpp
  23. +95 −0 src/3rd/ArduinoJson/include/ArduinoJson/Internals/JsonPrintable.hpp
  24. +29 −0 src/3rd/ArduinoJson/include/ArduinoJson/Internals/JsonVariantContent.hpp
  25. +36 −0 src/3rd/ArduinoJson/include/ArduinoJson/Internals/JsonVariantType.hpp
  26. +84 −0 src/3rd/ArduinoJson/include/ArduinoJson/Internals/JsonWriter.hpp
  27. +58 −0 src/3rd/ArduinoJson/include/ArduinoJson/Internals/List.hpp
  28. +40 −0 src/3rd/ArduinoJson/include/ArduinoJson/Internals/ListConstIterator.hpp
  29. +43 −0 src/3rd/ArduinoJson/include/ArduinoJson/Internals/ListIterator.hpp
  30. +26 −0 src/3rd/ArduinoJson/include/ArduinoJson/Internals/ListNode.hpp
  31. +46 −0 src/3rd/ArduinoJson/include/ArduinoJson/Internals/Prettyfier.hpp
  32. +34 −0 src/3rd/ArduinoJson/include/ArduinoJson/Internals/ReferenceType.hpp
  33. +30 −0 src/3rd/ArduinoJson/include/ArduinoJson/Internals/StaticStringBuilder.hpp
  34. +34 −0 src/3rd/ArduinoJson/include/ArduinoJson/Internals/StreamPrintAdapter.hpp
  35. +20 −0 src/3rd/ArduinoJson/include/ArduinoJson/Internals/Unparsed.hpp
  36. +135 −0 src/3rd/ArduinoJson/include/ArduinoJson/JsonArray.hpp
  37. +219 −0 src/3rd/ArduinoJson/include/ArduinoJson/JsonArray.ipp
  38. +72 −0 src/3rd/ArduinoJson/include/ArduinoJson/JsonArraySubscript.hpp
  39. +136 −0 src/3rd/ArduinoJson/include/ArduinoJson/JsonBuffer.hpp
  40. +151 −0 src/3rd/ArduinoJson/include/ArduinoJson/JsonObject.hpp
  41. +240 −0 src/3rd/ArduinoJson/include/ArduinoJson/JsonObject.ipp
  42. +24 −0 src/3rd/ArduinoJson/include/ArduinoJson/JsonObjectKey.hpp
  43. +88 −0 src/3rd/ArduinoJson/include/ArduinoJson/JsonObjectSubscript.hpp
  44. +19 −0 src/3rd/ArduinoJson/include/ArduinoJson/JsonPair.hpp
  45. +82 −0 src/3rd/ArduinoJson/include/ArduinoJson/JsonSubscriptBase.hpp
  46. +106 −0 src/3rd/ArduinoJson/include/ArduinoJson/JsonVariant.hpp
  47. +252 −0 src/3rd/ArduinoJson/include/ArduinoJson/JsonVariant.ipp
  48. +151 −0 src/3rd/ArduinoJson/include/ArduinoJson/JsonVariantBase.hpp
  49. +35 −0 src/3rd/ArduinoJson/include/ArduinoJson/StaticJsonBuffer.hpp
  50. +14 −0 src/3rd/ArduinoJson/keywords.txt
  51. +9 −0 src/3rd/ArduinoJson/library.properties
  52. +71 −0 src/3rd/ArduinoJson/src/Arduino/Print.cpp
  53. +13 −0 src/3rd/ArduinoJson/src/ArduinoJson.h
  54. +51 −0 src/3rd/ArduinoJson/src/Internals/Comments.cpp
  55. +12 −0 src/3rd/ArduinoJson/src/Internals/Encoding.cpp
  56. +29 −0 src/3rd/ArduinoJson/src/Internals/IndentedPrint.cpp
  57. +200 −0 src/3rd/ArduinoJson/src/Internals/JsonParser.cpp
  58. +49 −0 src/3rd/ArduinoJson/src/Internals/List.cpp
  59. +86 −0 src/3rd/ArduinoJson/src/Internals/Prettyfier.cpp
  60. +17 −0 src/3rd/ArduinoJson/src/Internals/StaticStringBuilder.cpp
  61. +53 −0 src/3rd/ArduinoJson/src/JsonArray.cpp
  62. +41 −0 src/3rd/ArduinoJson/src/JsonBuffer.cpp
  63. +71 −0 src/3rd/ArduinoJson/src/JsonObject.cpp
  64. +138 −0 src/3rd/ArduinoJson/src/JsonVariant.cpp
  65. +21 −0 src/3rd/Bounce2/LICENSE
  66. 0 src/3rd/Bounce2/LICENSE~
  67. +29 −0 src/3rd/Bounce2/keywords.txt
  68. +9 −0 src/3rd/Bounce2/library.properties
  69. +98 −0 src/3rd/Bounce2/src/Bounce2.cpp
  70. +78 −0 src/3rd/Bounce2/src/Bounce2.h
  71. +39 −0 src/3rd/PubSubClient/Homie Patch.txt
  72. +20 −0 src/3rd/PubSubClient/LICENSE.txt
  73. +30 −0 src/3rd/PubSubClient/keywords.txt
  74. +9 −0 src/3rd/PubSubClient/library.properties
  75. +590 −0 src/3rd/PubSubClient/src/PubSubClient.cpp
  76. +132 −0 src/3rd/PubSubClient/src/PubSubClient.h
  77. +109 −0 src/Homie.cpp
  78. +41 −0 src/Homie.h
  79. +27 −0 src/Homie/Blinker.cpp
  80. +19 −0 src/Homie/Blinker.hpp
  81. +24 −0 src/Homie/Boot.cpp
  82. +14 −0 src/Homie/Boot.hpp
  83. +135 −0 src/Homie/BootConfig.cpp
  84. +24 −0 src/Homie/BootConfig.hpp
  85. +192 −0 src/Homie/BootNormal.cpp
  86. +34 −0 src/Homie/BootNormal.hpp
  87. +69 −0 src/Homie/BootOta.cpp
  88. +19 −0 src/Homie/BootOta.hpp
  89. +58 −0 src/Homie/Config.cpp
  90. +29 −0 src/Homie/Config.hpp
  91. +58 −0 src/Homie/Constants.hpp
@@ -0,0 +1,21 @@
+The MIT License (MIT)
+
+Copyright (c) 2015 Marvin Roger
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
@@ -0,0 +1,162 @@
+# Homie
+
+![Homie logo](logo.png)
+
+An opiniated IoT framework for the ESP8266.
+
+## Features
+
+* Easy credentials configuration through a Web UI
+* Network tolerant with automatic reconnection
+* OTA support
+* Pretty straightforward sketches, a simple light for example:
+
+```c++
+#include <Homie.h>
+
+const int PIN_RELAY = D1;
+
+void inputHandler(String node, String property, String message) {
+ if (node != "light" || property != "on") {
+ return;
+ }
+
+ if (message == "true") {
+ digitalWrite(PIN_RELAY, HIGH);
+ } else if (message == "false") {
+ digitalWrite(PIN_RELAY, LOW);
+ }
+}
+
+void setup() {
+ pinMode(PIN_RELAY, OUTPUT);
+ digitalWrite(PIN_RELAY, LOW);
+ Homie.setVersion("1.0.0");
+ Homie.addNode("light", "light");
+ Homie.addSubscription("light", "on");
+ Homie.setInputHandler(inputHandler);
+ Homie.setup();
+}
+
+void loop() {
+ Homie.loop();
+}
+```
+
+## Requirements
+
+* An ESP8266
+* The [Arduino IDE for ESP8266](https://github.com/esp8266/Arduino) (version 2.0.0 minimum)
+
+## Installation
+
+1. Download the [latest version](https://github.com/marvinroger/homie/archive/master.zip)
+2. Load the `.zip` with **Sketch → Include Library → Add .ZIP Library**
+
+## How does it work?
+
+An Homie device has 3 modes of operation:
+
+1. The `config` mode is the initial one. It spawns an AP and a JSON webserver. A client can connect to it, get the list of available networks, and send the credentials (Wi-Fi SSID, password, and the Homie server hostname/IP). Once the Homie device receives the credentials, it boots into normal mode.
+
+2. The `normal` mode is the mode the device will be most of the time. It connects to the Wi-Fi, to the MQTT, it sends initial informations to the Homie server (like the local IP, the version of the firmware...) and it subscribes from the server to the subscriptions given (see `addSubscription()`) and to OTA events. It then runs the given `setup` function (see `setSetupFunction()`), and loops the given `loop` function (see `setLoopFunction()`). This provides a nice abstraction, as everything is handled in the lower level. If there is a network failure, it will try to auto-reconnect, endlessly. To return to the `config` mode, the user has to press the `FLASH` button of the ESP8266 board for 5 seconds.
+
+3. The `OTA` mode is triggered from the `normal` mode when the Homie server sends a version newer than the current firmware version (see `setVersion()`). It will reach the Homie server and download the latest firmware available. When it ends (either a success or a failure), it returns to `normal` mode.
+
+## API
+
+You don't have to instanciate an `Homie` instance, it is done internally.
+
+See examples folder for examples.
+
+### Core functions
+
+#### void .setup ()
+
+Setup Homie. Must be called once in `setup()`, after Homie is configured (`addNode`, `addSubscription`...) and when you have set the initial state of GPIOs.
+
+#### void .loop ()
+
+Handle Homie work. Must be called in `loop()`.
+
+**Never call `delay()` in the sketch loop() as it will be blocking, causing Homie to malfunction.**
+
+### Configuration functions
+
+#### void .setVersion (const char\* `version`)
+
+Set the version of the sketch. This is useful for OTA, as Homie will check against the server if there is a newer version.
+
+* **`version`**: Version of the sketch. Default value is `undefined`
+
+#### void .addNode (const char\* `name`, const char\* `type`)
+
+Add a node to the device. A device might have multiple nodes, like a temperature one and an humidity one. See the Wiki to see all node types and the properties it exposes.
+
+* **`name`**: Name of the node
+* **`type`**: Type of the node. See the Wiki
+
+#### void .addSubscription (const char \* `node`, const char\* `property`)
+
+Subscribe to a property. A device might want to subscribe to a property (like `level` for a `shutters` node for example).
+
+* **`node`**: Name of the node
+* **`property`**: Property to listen
+
+#### void .setInputHandler (void (\*`callback`)(String `node`, String `property`, String `message`))
+
+Set input handler for subscribed properties.
+
+* **`callback`**: Input handler
+* **`node`**: Name of the node
+* **`preoperty`**: Name of the property
+* **`message`**: Payload
+
+#### void .setResetFunction (void (\*`callback`)(void))
+
+Set the reset function. If you use a library that uses EEPROM for example, you will want to provide a function that clears the EEPROM.
+
+* **`callback`**: Reset function
+
+#### void .setResettable (bool `resettable`)
+
+Is the device resettable? This is useful at runtime, because you might want the device not to be resettable when you have another library that is doing some unfinished work, like moving shutters for example.
+
+* **`resettable`**: Is the device resettable? Default value is `true`
+
+#### void .setSetupFunction (void (\*`callback`)(void))
+
+You can provide the function that will be called when operating in normal mode (when the device is configured and connected).
+
+* **`callback`**: Setup function
+
+#### void .setLoopFunction (void (\*`callback`)(void))
+
+You can provide the function that will be looped in normal mode.
+
+* **`callback`**: Loop function
+
+#### void .reserveEeprom (int `bytes`)
+
+Homie uses EEPROM internally, and the ESP8266 needs to know how many bytes are going to be used. So you can reserve how many bytes you will use in EEPROM.
+
+* **`bytes`**: Number of bytes you will use
+
+### Runtime functions
+
+#### void .sendProperty (String `node`, String `property`, String `value`, bool `retained` = true)
+
+Using this function, you can send a value to a property, like a temperature for example.
+
+* **`node`**: Name of the node
+* **`property`**: Property to send
+* **`value`**: Payload
+* **`retained`**: Should the server retain this value, or is it a one-shot value?
+
+#### int .getEepromOffset ()
+
+As Homie uses EEPROM, first bytes of the EEPROM are used. This functions returns the first byte that is free for you to use.
+
+#### bool .readyToOperate ()
+
+Is the device in normal mode, configured and connected? You should not need this function. But maybe you will.
@@ -0,0 +1,29 @@
+#include <Homie.h>
+
+const int PIN_RELAY = D1;
+
+void inputHandler(String node, String property, String message) {
+ if (node != "light" || property != "on") {
+ return;
+ }
+
+ if (message == "true") {
+ digitalWrite(PIN_RELAY, HIGH);
+ } else if (message == "false") {
+ digitalWrite(PIN_RELAY, LOW);
+ }
+}
+
+void setup() {
+ pinMode(PIN_RELAY, OUTPUT);
+ digitalWrite(PIN_RELAY, LOW);
+ Homie.setVersion("1.0.0");
+ Homie.addNode("light", "light");
+ Homie.addSubscription("light", "on");
+ Homie.setInputHandler(inputHandler);
+ Homie.setup();
+}
+
+void loop() {
+ Homie.loop();
+}
@@ -0,0 +1,35 @@
+#include <Homie.h>
+
+const int TEMPERATURE_INTERVAL = 300;
+
+unsigned long last_temperature_sent = 0;
+
+void setupHandler() {
+ // Do what you want to prepare your sensor
+}
+
+void loopHandler() {
+ if ((millis() - last_temperature_sent >= TEMPERATURE_INTERVAL * 1000UL || last_temperature_sent == 0) && !shutters->moving()) {
+ float temperature = 22;
+ Serial.print("Temperature: ");
+ Serial.print(temperature);
+ Serial.println(" °C");
+ if (Homie.sendProperty("temperature", "temperature", String(temperature), true)) {
+ last_temperature_sent = millis();
+ } else {
+ Serial.println("Sending failed");
+ }
+ }
+}
+
+void setup() {
+ Homie.setVersion("1.0.0");
+ Homie.addNode("temperature", "temperature");
+ Homie.setSetupFunction(setupHandler);
+ Homie.setLoopFunction(loopHandler);
+ Homie.setup();
+}
+
+void loop() {
+ Homie.loop();
+}
@@ -0,0 +1,28 @@
+#######################################
+# Datatypes (KEYWORD1)
+#######################################
+
+Homie KEYWORD1
+
+#######################################
+# Methods and Functions (KEYWORD2)
+#######################################
+
+setup KEYWORD2
+loop KEYWORD2
+setVersion KEYWORD2
+addNode KEYWORD2
+setInputHandler KEYWORD2
+addSubscription KEYWORD2
+setSetupFunction KEYWORD2
+setLoopFunction KEYWORD2
+setResetFunction KEYWORD2
+reserveEeprom KEYWORD2
+readyToOperate KEYWORD2
+setResettable KEYWORD2
+sendProperty KEYWORD2
+getEepromOffset KEYWORD2
+
+#######################################
+# Constants (LITERAL1)
+#######################################
@@ -0,0 +1,9 @@
+name=Homie
+version=1.0.0
+author=Marvin Roger
+maintainer=Marvin Roger
+sentence=An IOT solution for ESP8266.
+paragraph=Like this project? Please star it on GitHub!
+category=Device Control
+url=https://github.com/marvinroger/Homie
+architectures=esp8266
@@ -0,0 +1,10 @@
+The MIT License (MIT)
+---------------------
+
+Copyright © 2014-2015 Benoit BLANCHON
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,12 @@
+// Copyright Benoit Blanchon 2014
+// MIT License
+//
+// Arduino JSON library
+// https://github.com/bblanchon/ArduinoJson
+
+#include "ArduinoJson/DynamicJsonBuffer.hpp"
+#include "ArduinoJson/JsonArray.hpp"
+#include "ArduinoJson/JsonObject.hpp"
+#include "ArduinoJson/StaticJsonBuffer.hpp"
+
+using namespace ArduinoJson;
@@ -0,0 +1,32 @@
+// Copyright Benoit Blanchon 2014-2015
+// MIT License
+//
+// Arduino JSON library
+// https://github.com/bblanchon/ArduinoJson
+
+#pragma once
+
+#ifndef ARDUINO
+
+#include <stddef.h>
+#include <stdint.h>
+
+// This class reproduces Arduino's Print class
+class Print {
+ public:
+ virtual ~Print() {}
+
+ virtual size_t write(uint8_t) = 0;
+
+ size_t print(const char[]);
+ size_t print(double, int = 2);
+ size_t print(int);
+ size_t print(long);
+ size_t println();
+};
+
+#else
+
+#include <Print.h>
+
+#endif
@@ -0,0 +1,18 @@
+// Copyright Benoit Blanchon 2014-2015
+// MIT License
+//
+// Arduino JSON library
+// https://github.com/bblanchon/ArduinoJson
+
+#pragma once
+
+#ifndef ARDUINO
+
+#include <string>
+typedef std::string String;
+
+#else
+
+#include <WString.h>
+
+#endif
@@ -0,0 +1,17 @@
+// Copyright Benoit Blanchon 2014-2015
+// MIT License
+//
+// Arduino JSON library
+// https://github.com/bblanchon/ArduinoJson
+
+#pragma once
+
+#include "Internals/BlockJsonBuffer.hpp"
+
+namespace ArduinoJson {
+// Implements a JsonBuffer with dynamic memory allocation.
+// You are strongly encouraged to consider using StaticJsonBuffer which is much
+// more suitable for embedded systems.
+typedef Internals::BlockJsonBuffer<Internals::DefaultAllocator>
+ DynamicJsonBuffer;
+}
Oops, something went wrong.

0 comments on commit 4ea31a7

Please sign in to comment.