-
Notifications
You must be signed in to change notification settings - Fork 279
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ca661e0
commit af9a9eb
Showing
6 changed files
with
131 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
This a simple example of the aREST Library for the ESP8266 WiFi chip. | ||
This example illustrate the cloud part of aREST that makes the board accessible from anywhere | ||
See the README file for more details. | ||
Written in 2015 by Marco Schwartz under a GPL license. | ||
*/ | ||
|
||
// Import required libraries | ||
#include <ESP8266WiFi.h> | ||
#include <PubSubClient.h> | ||
#include <aREST.h> | ||
|
||
// Clients | ||
WiFiClient espClient; | ||
PubSubClient client(espClient); | ||
|
||
// Create aREST instance | ||
aREST rest = aREST(client); | ||
|
||
// Unique ID to identify the device for cloud.arest.io | ||
char* device_id = "unique_device_id"; | ||
|
||
// WiFi parameters | ||
const char* ssid = "your_wifi_network_name"; | ||
const char* password = "your_wifi_network_password"; | ||
|
||
// Variables to be exposed to the API | ||
int temperature; | ||
int humidity; | ||
|
||
// Functions | ||
void callback(char* topic, byte* payload, unsigned int length); | ||
|
||
void setup(void) | ||
{ | ||
// Start Serial | ||
Serial.begin(115200); | ||
|
||
// Set callback | ||
client.setCallback(callback); | ||
|
||
// Init variables and expose them to REST API | ||
temperature = 24; | ||
humidity = 40; | ||
rest.variable("temperature",&temperature); | ||
rest.variable("humidity",&humidity); | ||
|
||
// Give name and ID to device | ||
rest.set_id(device_id); | ||
rest.set_name("esp8266"); | ||
|
||
// Connect to WiFi | ||
WiFi.begin(ssid, password); | ||
while (WiFi.status() != WL_CONNECTED) { | ||
delay(500); | ||
Serial.print("."); | ||
} | ||
Serial.println(""); | ||
Serial.println("WiFi connected"); | ||
|
||
// Set output topic | ||
char* out_topic = rest.get_topic(); | ||
|
||
} | ||
|
||
void loop() { | ||
|
||
// Connect to the cloud | ||
rest.loop(client); | ||
|
||
} | ||
|
||
// Handles message arrived on subscribed topic(s) | ||
void callback(char* topic, byte* payload, unsigned int length) { | ||
|
||
rest.handle_callback(client, topic, payload, length); | ||
|
||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
name=aREST | ||
version=2.0.0 | ||
version=2.0.1 | ||
author=Marco Schwartz | ||
maintainer=Marco Schwartz <[email protected]> | ||
sentence=RESTful API for the Arduino platform. | ||
|