diff --git a/examples/Datastore/Logging/Logging-esp32/Logging-esp32.ino b/examples/Datastore/Logging/Logging-esp32/Logging-esp32.ino deleted file mode 100644 index dabf7dd..0000000 --- a/examples/Datastore/Logging/Logging-esp32/Logging-esp32.ino +++ /dev/null @@ -1,131 +0,0 @@ -/** - * @file Logging-esp32.ino - * @date 21.06.2020 - * @author Grandeur Technologies - * - * Copyright (c) 2019 Grandeur Technologies LLP. All rights reserved. - * This file is part of the Arduino SDK for Grandeur. - * - * Grandeur.h is used for device's communication to Grandeur. - * WiFi.h is used for handling device's WiFi. - * - * This example illustrates the insertion of data into the datastore. - * It would be useful in logging data on the cloud to visualize it in form of tables or graphs. -*/ - -#include -#include - -// Device's connection configurations -String apiKey = "YOUR-PROJECT-APIKEY"; -String token = "YOUR-ACCESS-TOKEN"; -const char *ssid = "YOUR-WIFI-SSID"; -const char *passphrase = "YOUR-WIFI-PASSWORD"; - -// Declaring and initializing other variables -Grandeur::Project myProject; -Grandeur::Project::Datastore myDatastore; -int statePin = 4; -unsigned long current = millis(); - -// Function prototypes -void WiFiEventCallback(WiFiEvent_t event); -void setupWiFi(void); -void connectionCallback(bool status); -void insertCallback(const char *code); - -void setup() -{ - Serial.begin(9600); - // This sets up the device WiFi. - setupWiFi(); - // This initializes the SDK's configurations and returns a reference to my project on Grandeur. - myProject = grandeur.init(apiKey, token); - // Getting object of Datastore class. - myDatastore = myProject.datastore(); - // This schedules the connectionCallback() function to be called when connection with Grandeur - // is made/broken. - myProject.onConnection(connectionCallback); -} - -void loop() -{ - if (myProject.isConnected()) - { - if (millis() - current >= 5000) - { - // This if-condition makes sure that the code inside this block runs only after - // every five seconds. - Var logs; - logs[0]["voltage"] = analogRead(A0); - myDatastore.collection("logs").insert(logs, insertCallback); - // This updates the millis counter for - // the five seconds scheduler. - current = millis(); - } - } - - // The SDK only runs when the WiFi is connected. - if (WiFi.status() == WL_CONNECTED) - project.loop(); -} - -void WiFiEventCallback(WiFiEvent_t event) -{ - switch (event) - { - case SYSTEM_EVENT_STA_GOT_IP: - // This runs when the device connects with WiFi. - Serial.printf("\nDevice has successfully connected to WiFi. Its IP Address is: %s\n", - WiFi.localIP().toString().c_str()); - break; - case SYSTEM_EVENT_STA_DISCONNECTED: - // This runs when the device disconnects with WiFi. - Serial.println("Device is disconnected from WiFi."); - break; - default: - break; - } -} - -void setupWiFi(void) -{ - // Disconnecting WiFi if it"s already connected - WiFi.disconnect(); - // Setting it to Station mode which basically scans for nearby WiFi routers - WiFi.mode(WIFI_STA); - // Setting WiFi event handler - WiFi.onEvent(WiFiEventCallback); - // Begin connecting to WiFi - WiFi.begin(ssid, passphrase); - Serial.printf("\nDevice is connecting to WiFi using SSID %s and Passphrase %s.\n", ssid, passphrase); -} - -void connectionCallback(bool status) -{ - switch (status) - { - case CONNECTED: - // On successful connection with Grandeur, we initialize the device's *state*. - // To do that, we set the *state pin* to the value of *state* from Grandeur. - Serial.println("Device is connected with Grandeur."); - Serial.println("Logging voltage to Grandeur..."); - break; - case DISCONNECTED: - Serial.println("Device's connection with Grandeur is broken."); - break; - } -} - -void insertCallback(const char *code) -{ - // This function prints if the logs were successfully inserted into the datastore or not. - if (strcmp(code, "DATASTORE-DOCUMENTS-INSERTED") == 0) - { - Serial.printf("Voltage is successfully logged to Grandeur."); - return; - } - // If insertion is not successful. - Serial.println("Failed to log voltage"); - return; -} \ No newline at end of file diff --git a/examples/Datastore/Logging/Logging-esp8266/Logging-esp8266.ino b/examples/Datastore/Logging/Logging-esp8266/Logging-esp8266.ino deleted file mode 100644 index f7dee4b..0000000 --- a/examples/Datastore/Logging/Logging-esp8266/Logging-esp8266.ino +++ /dev/null @@ -1,125 +0,0 @@ -/** - * @file Logging-esp8266.ino - * @date 21.06.2020 - * @author Grandeur Technologies - * - * Copyright (c) 2019 Grandeur Technologies LLP. All rights reserved. - * This file is part of the Arduino SDK for Grandeur. - * - * Grandeur.h is used for device's communication to Grandeur. - * ESP8266WiFi.h is used for handling device's WiFi. - * - * This example illustrates the insertion of data into the datastore. - * It would be useful in logging data on the cloud to visualize it in form of tables or graphs. -*/ - -#include -#include - -// Device's connection configurations -String apiKey = "YOUR-PROJECT-APIKEY"; -String deviceID = "YOUR-DEVICE-ID"; -String token = "YOUR-ACCESS-TOKEN"; -const char *ssid = "YOUR-WIFI-SSID"; -const char *passphrase = "YOUR-WIFI-PASSWORD"; - -// Declaring and initializing other variables -Grandeur::Project myProject; -Grandeur::Project::Datastore myDatastore; -WiFiEventHandler onWiFiConnectedHandler; -WiFiEventHandler onWiFiDisconnectedHandler; -int statePin = D0; -unsigned long current = millis(); - -// Function prototypes -void setupWiFi(void); -void connectionCallback(bool status); -void insertCallback(const char *code); - -void setup() -{ - Serial.begin(9600); - // This sets up the device WiFi. - setupWiFi(); - // This initializes the SDK's configurations and returns a reference to my project on Grandeur. - myProject = grandeur.init(apiKey, token); - // Getting object of Datastore class. - myDatastore = myProject.datastore(); - // This schedules the connectionCallback() function to be called when connection with Grandeur - // is made/broken. - myProject.onConnection(connectionCallback); -} - -void loop() -{ - if (myProject.isConnected()) - { - if (millis() - current >= 5000) - { - // This if-condition makes sure that the code inside this block runs only after - // every five seconds. - Var logs; - logs[0]["voltage"] = analogRead(A0); - myDatastore.collection("logs").insert(logs, insertCallback); - // This updates the millis counter for - // the five seconds scheduler. - current = millis(); - } - } - - // The SDK only runs when the WiFi is connected. - if (WiFi.status() == WL_CONNECTED) - project.loop(); -} - -void setupWiFi(void) -{ - // Disconnecting WiFi if it"s already connected - WiFi.disconnect(); - // Setting it to Station mode which basically scans for nearby WiFi routers - WiFi.mode(WIFI_STA); - // Setting WiFi event handlers - onWiFiConnectedHandler = WiFi.onStationModeGotIP([](const WiFiEventStationModeGotIP &event) - { - // This runs when the device connects with WiFi. - Serial.printf("\nDevice has successfully connected to WiFi. Its IP Address is: %s\n", - WiFi.localIP().toString().c_str()); - }); - onWiFiDisconnectedHandler = WiFi.onStationModeDisconnected([](const WiFiEventStationModeDisconnected &event) - { - // This runs when the device disconnects with WiFi. - Serial.println("Device is disconnected from WiFi."); - }); - // Begin connecting to WiFi - WiFi.begin(ssid, passphrase); - Serial.printf("\nDevice is connecting to WiFi using SSID %s and Passphrase %s.\n", ssid, passphrase); -} - -void connectionCallback(bool status) -{ - switch (status) - { - case CONNECTED: - // On successful connection with Grandeur, we initialize the device's *state*. - // To do that, we set the *state pin* to the value of *state* from Grandeur. - Serial.println("Device is connected with Grandeur."); - Serial.println("Logging voltage to Grandeur..."); - break; - case DISCONNECTED: - Serial.println("Device's connection with Grandeur is broken."); - break; - } -} - -void insertCallback(const char *code) -{ - // This function prints if the logs were successfully inserted into the datastore or not. - if (strcmp(code, "DATASTORE-DOCUMENTS-INSERTED") == 0) - { - Serial.printf("Voltage is successfully logged to Grandeur.\n"); - return; - } - // If insertion is not successful. - Serial.println("Failed to log voltage"); - return; -} \ No newline at end of file diff --git a/examples/Datastore/Searching/Searching-esp32/Searching-esp32.ino b/examples/Datastore/Searching/Searching-esp32/Searching-esp32.ino deleted file mode 100644 index 4cb6c26..0000000 --- a/examples/Datastore/Searching/Searching-esp32/Searching-esp32.ino +++ /dev/null @@ -1,127 +0,0 @@ -/** - * @file Searching-esp32.ino - * @date 21.06.2020 - * @author Grandeur Technologies - * - * Copyright (c) 2019 Grandeur Technologies LLP. All rights reserved. - * This file is part of the Arduino SDK for Grandeur. - * - * Grandeur.h is used for device's communication to Grandeur. - * WiFi.h is used for handling device's WiFi. - * - * This example illustrates the finding documents in datastore. - * It would be useful in setting device to a previous state or just displaying the data on an LCD. -*/ - -#include -#include - -// Device's connection configurations -String apiKey = "YOUR-PROJECT-APIKEY"; -String token = "YOUR-ACCESS-TOKEN"; -const char* ssid = "YOUR-WIFI-SSID"; -const char* passphrase = "YOUR-WIFI-PASSWORD"; - -// Declaring and initializing other variables -Grandeur::Project myProject; -Grandeur::Project::Datastore myDatastore; -int statePin = 4; -unsigned long current = millis(); - -// Function prototypes -void WiFiEventCallback(WiFiEvent_t event); -void setupWiFi(void); -void connectionCallback(bool status); -void searchCallback(const char* code, Var result); - -void setup() { - Serial.begin(9600); - // This sets up the device WiFi. - setupWiFi(); - // This initializes the SDK's configurations and returns a reference to my project on Grandeur. - myProject = grandeur.init(apiKey, token); - // Getting object of Datastore class. - myDatastore = myProject.datastore(); - // This schedules the connectionCallback() function to be called when connection with Grandeur - // is made/broken. - myProject.onConnection(connectionCallback); -} - -void loop() { - if(myProject.isConnected()) { - if(millis() - current >= 5000) { - // This if-condition makes sure that the code inside this block runs only after - // every five seconds. - // This fetches 1st page of all the documents stored in the datastore. - Var filter; - filter["voltage"]["$gt"] = 1; - myDatastore.collection("logs").search(filter, {}, 0, searchCallback); - // This updates the millis counter for - // the five seconds scheduler. - current = millis(); - } - } - - // The SDK only runs when the WiFi is connected. - if(WiFi.status() == WL_CONNECTED) project.loop(); -} - -void WiFiEventCallback(WiFiEvent_t event) { - switch(event) { - case SYSTEM_EVENT_STA_GOT_IP: - // This runs when the device connects with WiFi. - Serial.printf("\nDevice has successfully connected to WiFi. Its IP Address is: %s\n", - WiFi.localIP().toString().c_str()); - break; - case SYSTEM_EVENT_STA_DISCONNECTED: - // This runs when the device disconnects with WiFi. - Serial.println("Device is disconnected from WiFi."); - break; - default: break; - } -} - -void setupWiFi(void) { - // Disconnecting WiFi if it"s already connected - WiFi.disconnect(); - // Setting it to Station mode which basically scans for nearby WiFi routers - WiFi.mode(WIFI_STA); - // Setting WiFi event handlers - WiFi.onEvent(WiFiEventCallback); - // Begin connecting to WiFi - WiFi.begin(ssid, passphrase); - Serial.printf("\nDevice is connecting to WiFi using SSID %s and Passphrase %s.\n", ssid, passphrase); -} - -void connectionCallback(bool status) { - switch(status) { - case CONNECTED: - // On successful connection with Grandeur, we initialize the device's *state*. - // To do that, we set the *state pin* to the value of *state* from Grandeur. - Serial.println("Device is connected with Grandeur."); - Serial.println("Logging voltage to Grandeur..."); - break; - case DISCONNECTED: - Serial.println("Device's connection with Grandeur is broken."); - break; - } -} - -void searchCallback(const char* code, Var result) { - // This function prints if the datastore search for the docs was successfully or not. - if(searchResult["code"] == "DATASTORE-DOCUMENTS-FETCHED") { - Serial.print("Documents fetched from Grandeur: "); - Serial.println(searchResult["documents"].length()); - // Printing all the fetched documents. - for(int i = 0; i < searchResult["documents"].length(); i++) { - Serial.println(JSON.stringify(searchResult["documents"][i]).c_str()); - // Just to keep the watchdog timer from tripping. - delay(1); - } - Serial.println(""); - return; - } - // If search is not successful. - Serial.println("Failed to fetch documents."); - return; -} diff --git a/examples/Datastore/Searching/Searching-esp8266/Searching-esp8266.ino b/examples/Datastore/Searching/Searching-esp8266/Searching-esp8266.ino deleted file mode 100644 index 30ff895..0000000 --- a/examples/Datastore/Searching/Searching-esp8266/Searching-esp8266.ino +++ /dev/null @@ -1,134 +0,0 @@ -/** - * @file Searching-esp8266.ino - * @date 21.06.2020 - * @author Grandeur Technologies - * - * Copyright (c) 2019 Grandeur Technologies LLP. All rights reserved. - * This file is part of the Arduino SDK for Grandeur. - * - * Grandeur.h is used for device's communication to Grandeur. - * ESP8266WiFi.h is used for handling device's WiFi. - * - * This example illustrates the insertion of data into the datastore. - * It would be useful in logging data on the cloud to visualize it in form of tables or graphs. -*/ - -#include -#include - -// Device's connection configurations -String apiKey = "YOUR-PROJECT-APIKEY"; -String token = "YOUR-ACCESS-TOKEN"; -String ssid = "YOUR-WIFI-SSID"; -String passphrase = "YOUR-WIFI-PASSWORD"; - -// Declaring and initializing other variables -Grandeur::Project myProject; -Grandeur::Project::Datastore myDatastore; -WiFiEventHandler onWiFiConnectedHandler; -WiFiEventHandler onWiFiDisconnectedHandler; -int statePin = D0; -unsigned long current = millis(); - -// Function prototypes -void setupWiFi(void); -void connectionCallback(bool status); -void searchCallback(const char *code, Var result); - -void setup() -{ - Serial.begin(9600); - // This sets up the device WiFi. - setupWiFi(); - // This initializes the SDK's configurations and returns a reference to my project on Grandeur. - myProject = grandeur.init(apiKey, token); - // Getting object of Datastore class. - myDatastore = myProject.datastore(); - // This schedules the connectionCallback() function to be called when connection with Grandeur - // is made/broken. - myProject.onConnection(connectionCallback); -} - -void loop() -{ - if (myProject.isConnected()) - { - if (millis() - current >= 5000) - { - // This if-condition makes sure that the code inside this block runs only after - // every five seconds. - // This fetches 1st page of all the documents stored in the datastore. - myDatastore.collection("logs").search({}, {}, 0, searchCallback); - // This updates the millis counter for - // the five seconds scheduler. - current = millis(); - } - } - - // The SDK only runs when the WiFi is connected. - if(WiFi.status() == WL_CONNECTED) project.loop(); -} - -void setupWiFi(void) -{ - // Disconnecting WiFi if it"s already connected - WiFi.disconnect(); - // Setting it to Station mode which basically scans for nearby WiFi routers - WiFi.mode(WIFI_STA); - // Setting WiFi event handlers - onWiFiConnectedHandler = WiFi.onStationModeGotIP([](const WiFiEventStationModeGotIP &event) - { - // This runs when the device connects with WiFi. - Serial.printf("\nDevice has successfully connected to WiFi. Its IP Address is: %s\n", - WiFi.localIP().toString().c_str()); - }); - onWiFiDisconnectedHandler = WiFi.onStationModeDisconnected([](const WiFiEventStationModeDisconnected &event) - { - // This runs when the device disconnects with WiFi. - Serial.println("Device is disconnected from WiFi."); - }); - // Begin connecting to WiFi - WiFi.begin(ssid, passphrase); - Serial.printf("\nDevice is connecting to WiFi using SSID %s and Passphrase %s.\n", ssid, passphrase); -} - -void connectionCallback(bool status) -{ - switch (status) - { - case CONNECTED: - // On successful connection with Grandeur, we initialize the device's *state*. - // To do that, we set the *state pin* to the value of *state* from Grandeur. - Serial.println("Device is connected with Grandeur."); - Serial.println("Searching documents on Grandeur..."); - break; - case DISCONNECTED: - Serial.println("Device's connection with Grandeur is broken."); - break; - } -} - -void searchCallback(const char *code, Var result) -{ - // This function prints if the datastore search for the docs was successfully or not. - if (strcmp(code, "DATASTORE-DOCUMENTS-FETCHED") == 0) - { - Serial.print("Total number of documents that matched the query: "); - Serial.println(result["nDocuments"]); - Serial.print("Number of documents fetched: "); // Will always be 20 if nDocuments > 20 - Serial.println(result["documents"].length()); - Serial.println("------------------------DOCUMENTS------------------------"); - // Printing all the fetched documents. - for (int i = 0; i < result["documents"].length(); i++) - { - Serial.println(JSON.stringify(result["documents"][i]).c_str()); - // Just to keep the watchdog timer from tripping. - delay(1); - } - Serial.println("---------------------------------------------------------"); - return; - } - // If search is not successful. - Serial.println("Failed to fetch documents."); - return; -} \ No newline at end of file diff --git a/examples/CrossListening/CrossListening-esp32/CrossListening-esp32.ino b/examples/esp32/ControlAndMonitorDevice/ControlAndMonitorDevice.ino similarity index 89% rename from examples/CrossListening/CrossListening-esp32/CrossListening-esp32.ino rename to examples/esp32/ControlAndMonitorDevice/ControlAndMonitorDevice.ino index daf5c31..763d056 100644 --- a/examples/CrossListening/CrossListening-esp32/CrossListening-esp32.ino +++ b/examples/esp32/ControlAndMonitorDevice/ControlAndMonitorDevice.ino @@ -1,5 +1,5 @@ /** - * @file CrossListening-esp32.ino + * @file ControlAndMonitorDevice.ino * @date 21.02.2021 * @author Grandeur Technologies * @@ -8,16 +8,14 @@ * * Grandeur.h is used for device's communication with Grandeur. * WiFi.h is used for handling device's WiFi. - * - * Cross listening means when the device listens for updates from the app and the app - * listens for updates from the device. + * * This example illustrates pretty much every basic thing you'd need in order to monitor / * control your device through Grandeur. Here are some of those: * 1. Listen to Grandeur for updates in device variables. * 2. Publish updates in variables to Grandeur every 5 seconds. * 3. Running the SDK only when a certain condition is true; in our case, if the WiFi is connected. * - * After uploading this sketch to your ESP, go to https://canvas.grandeur.tech and add a button and + * After uploading this sketch to your ESP, go to your device's canvas and add a button and * a display to control state and monitor voltage variable, respectively. */ @@ -25,11 +23,11 @@ #include // Device's connection configurations: -String apiKey = "YOUR-PROJECT-APIKEY"; -String deviceID = "YOUR-DEVICE-ID"; -String token = "YOUR-ACCESS-TOKEN"; -const char *ssid = "YOUR-WIFI-SSID"; -const char *passphrase = "YOUR-WIFI-PASSWORD"; +String apiKey = YOUR_PROJECT_APIKEY; // Copy from https://console.grandeur.dev/access +String deviceID = YOUR_DEVICE_ID; // Copy your device ID from https://console.grandeur.dev +String token = YOUR_DEVICE_TOKEN; // Copy when you register a new device +const char *ssid = YOUR_WIFI_SSID; +const char *passphrase = YOUR_WIFI_PASSWORD; // Handles our 5 second timer in loop(). unsigned long currentTime = millis(); @@ -55,7 +53,7 @@ void afterVoltageIsUpdated(const char *code, int voltage); void setup() { - .begin(9600); + Serial.begin(9600); startWiFi(); // This initializes the SDK's configurations and returns reference to your project. project = grandeur.init(apiKey, token); diff --git a/examples/DashListening-Device/DashListening-Device-esp32/DashListening-Device-esp32.ino b/examples/esp32/ControlDevice/ControlDevice.ino similarity index 87% rename from examples/DashListening-Device/DashListening-Device-esp32/DashListening-Device-esp32.ino rename to examples/esp32/ControlDevice/ControlDevice.ino index 3560d0b..30f384d 100644 --- a/examples/DashListening-Device/DashListening-Device-esp32/DashListening-Device-esp32.ino +++ b/examples/esp32/ControlDevice/ControlDevice.ino @@ -1,5 +1,5 @@ /** - * @file DashListening-Device-esp32.ino + * @file ControlDevice.ino * @date 21.02.2021 * @author Grandeur Technologies * @@ -9,12 +9,11 @@ * Grandeur.h is used for device's communication with Grandeur. * WiFi.h is used for handling device's WiFi. * - * Dash listening is for one-way listening. * This example illustrates the use case of a device listening for updates from the app. * It would be useful in building an INTERNET SWITCH to help you control your device without * caring about how your device responds to your commands. * - * After uploading this sketch to your ESP, go to https://canvas.grandeur.tech and add a button + * After uploading this sketch to your ESP, go to your device's canvas and add a button * to control the state variable. */ @@ -22,11 +21,11 @@ #include // Device's connection configurations: -String apiKey = "YOUR-PROJECT-APIKEY"; -String deviceID = "YOUR-DEVICE-ID"; -String token = "YOUR-ACCESS-TOKEN"; -const char *ssid = "YOUR-WIFI-SSID"; -const char *passphrase = "YOUR-WIFI-PASSWORD"; +String apiKey = YOUR_PROJECT_APIKEY; // Copy from https://console.grandeur.dev/access +String deviceID = YOUR_DEVICE_ID; // Copy your device ID from https://console.grandeur.dev +String token = YOUR_DEVICE_TOKEN; // Copy when you register a new device +const char *ssid = YOUR_WIFI_SSID; +const char *passphrase = YOUR_WIFI_PASSWORD; // Handles our 5 second timer in loop(). unsigned long currentTime = millis(); diff --git a/examples/HelloGrandeur/HelloGrandeur-esp32/HelloGrandeur-esp32.ino b/examples/esp32/HelloGrandeur/HelloGrandeur.ino similarity index 82% rename from examples/HelloGrandeur/HelloGrandeur-esp32/HelloGrandeur-esp32.ino rename to examples/esp32/HelloGrandeur/HelloGrandeur.ino index 8972d69..76f1da9 100644 --- a/examples/HelloGrandeur/HelloGrandeur-esp32/HelloGrandeur-esp32.ino +++ b/examples/esp32/HelloGrandeur/HelloGrandeur.ino @@ -1,5 +1,5 @@ /** - * @file HelloGrandeur-esp32.ino + * @file HelloGrandeur.ino * @date 21.02.2021 * @author Grandeur Technologies * @@ -16,11 +16,11 @@ #include // Device's connection configurations -String apiKey = "YOUR-PROJECT-APIKEY"; -String deviceID = "YOUR-DEVICE-ID"; -String token = "YOUR-ACCESS-TOKEN"; -const char* ssid = "YOUR-WIFI-SSID"; -const char* passphrase = "YOUR-WIFI-PASSWORD"; +String apiKey = YOUR_PROJECT_APIKEY; // Copy from https://console.grandeur.dev/access +String deviceID = YOUR_DEVICE_ID; // Copy your device ID from https://console.grandeur.dev +String token = YOUR_DEVICE_TOKEN; // Copy when you register a new device +const char* ssid = YOUR_WIFI_SSID; +const char* passphrase = YOUR_WIFI_PASSWORD; // Object of Grandeur project. Grandeur::Project project; @@ -53,7 +53,7 @@ void loop() { // project.device(deviceID).data().get("state", getStateCallback); - Serial.println("Read the docs at https://github.com/grandeurtech/arduino-sdk."); + Serial.println("Read the docs at https://docs.grandeur.dev/references/device-sdk."); Serial.println("Also checkout other examples: \n- DashListening-Device \n- DashListening-App \n- CrossListening.\n"); } // This runs the SDK only when the WiFi is connected. diff --git a/examples/DashListening-App/DashListening-App-esp32/DashListening-App-esp32.ino b/examples/esp32/MonitorDevice/MonitorDevice.ino similarity index 88% rename from examples/DashListening-App/DashListening-App-esp32/DashListening-App-esp32.ino rename to examples/esp32/MonitorDevice/MonitorDevice.ino index 397b45a..917aa88 100644 --- a/examples/DashListening-App/DashListening-App-esp32/DashListening-App-esp32.ino +++ b/examples/esp32/MonitorDevice/MonitorDevice.ino @@ -1,5 +1,5 @@ /** - * @file DashListening-App-esp32.ino + * @file MonitorDevice.ino * @date 21.02.2021 * @author Grandeur Technologies * @@ -9,12 +9,11 @@ * Grandeur.h is used for device's communication with Grandeur. * WiFi.h is used for handling device's WiFi. * - * Dash listening is for one-way listening. * This example illustrates the use case of an app listening for updates from the device. * It would be useful in building a DEVICE MONITOR which would show how your devices are * behaving in terms of their energy units consumed for example. * - * After uploading this sketch to your ESP, go to https://canvas.grandeur.tech and add + * After uploading this sketch to your ESP, go to your device's canvas and add * a display to monitor the voltage variable. */ @@ -22,11 +21,11 @@ #include // Device's connection configurations: -String apiKey = "YOUR-PROJECT-APIKEY"; -String deviceID = "YOUR-DEVICE-ID"; -String token = "YOUR-ACCESS-TOKEN"; -const char *ssid = "YOUR-WIFI-SSID"; -const char *passphrase = "YOUR-WIFI-PASSWORD"; +String apiKey = YOUR_PROJECT_APIKEY; // Copy from https://console.grandeur.dev/access +String deviceID = YOUR_DEVICE_ID; // Copy your device ID from https://console.grandeur.dev +String token = YOUR_DEVICE_TOKEN; // Copy when you register a new device +const char *ssid = YOUR_WIFI_SSID; +const char *passphrase = YOUR_WIFI_PASSWORD; // Handles our 5 second timer in loop(). unsigned long currentTime = millis(); diff --git a/examples/CrossListening/CrossListening-esp8266/CrossListening-esp8266.ino b/examples/esp8266/ControlAndMonitorDevice/ControlAndMonitorDevice.ino similarity index 90% rename from examples/CrossListening/CrossListening-esp8266/CrossListening-esp8266.ino rename to examples/esp8266/ControlAndMonitorDevice/ControlAndMonitorDevice.ino index 45213c8..a9c99ed 100644 --- a/examples/CrossListening/CrossListening-esp8266/CrossListening-esp8266.ino +++ b/examples/esp8266/ControlAndMonitorDevice/ControlAndMonitorDevice.ino @@ -1,5 +1,5 @@ /** - * @file CrossListening-esp8266.ino + * @file ControlAndMonitorDevice.ino * @date 21.02.2021 * @author Grandeur Technologies * @@ -9,15 +9,13 @@ * Grandeur.h is used for device's communication with Grandeur. * ESP8266WiFi.h is used for handling device's WiFi. * - * Cross listening means when the device listens for updates from the app and the app - * listens for updates from the device. * This example illustrates pretty much every basic thing you'd need in order to monitor / * control your device through Grandeur. Here are some of those: * 1. Listen to Grandeur for updates in device variables. * 2. Publish updates in variables to Grandeur every 5 seconds. * 3. Running the SDK only when a certain condition is true; in our case, if the WiFi is connected. * - * After uploading this sketch to your ESP, go to https://canvas.grandeur.tech and add a button and + * After uploading this sketch to your ESP, go to your device's canvas and add a button and * a display to control state and monitor voltage variable, respectively. */ @@ -25,11 +23,11 @@ #include // Device's connection configurations: -String apiKey = "YOUR-PROJECT-APIKEY"; -String deviceID = "YOUR-DEVICE-ID"; -String token = "YOUR-ACCESS-TOKEN"; -const char *ssid = "YOUR-WIFI-SSID"; -const char *passphrase = "YOUR-WIFI-PASSWORD"; +String apiKey = YOUR_PROJECT_APIKEY; // Copy from https://console.grandeur.dev/access +String deviceID = YOUR_DEVICE_ID; // Copy your device ID from https://console.grandeur.dev +String token = YOUR_DEVICE_TOKEN; // Copy when you register a new device +const char *ssid = YOUR_WIFI_SSID; +const char *passphrase = YOUR_WIFI_PASSWORD; // Handles our 5 second timer in loop(). unsigned long currentTime = millis(); diff --git a/examples/DashListening-Device/DashListening-Device-esp8266/DashListening-Device-esp8266.ino b/examples/esp8266/ControlDevice/ControlDevice.ino similarity index 89% rename from examples/DashListening-Device/DashListening-Device-esp8266/DashListening-Device-esp8266.ino rename to examples/esp8266/ControlDevice/ControlDevice.ino index f980bfe..9cdf26b 100644 --- a/examples/DashListening-Device/DashListening-Device-esp8266/DashListening-Device-esp8266.ino +++ b/examples/esp8266/ControlDevice/ControlDevice.ino @@ -1,5 +1,5 @@ /** - * @file DashListening-Device-esp8266.ino + * @file ControlDevice.ino * @date 21.02.2021 * @author Grandeur Technologies * @@ -9,23 +9,22 @@ * Grandeur.h is used for device's communication with Grandeur. * ESP8266WiFi.h is used for handling device's WiFi. * - * Dash listening is for one-way listening. * This example illustrates the use case of a device listening for updates from the app. * It would be useful in building an INTERNET SWITCH to help you control your device without * caring about how your device responds to your commands. * - * After uploading this sketch to your ESP, go to https://canvas.grandeur.tech and add a button + * After uploading this sketch to your ESP, go to your device's canvas and add a button * to control the state variable. */ #include #include // Device's connection configurations: -String apiKey = "YOUR-PROJECT-APIKEY"; -String deviceID = "YOUR-DEVICE-ID"; -String token = "YOUR-ACCESS-TOKEN"; -const char *ssid = "YOUR-WIFI-SSID"; -const char *passphrase = "YOUR-WIFI-PASSWORD"; +String apiKey = YOUR_PROJECT_APIKEY; // Copy from https://console.grandeur.dev/access +String deviceID = YOUR_DEVICE_ID; // Copy your device ID from https://console.grandeur.dev +String token = YOUR_DEVICE_TOKEN; // Copy when you register a new device +const char *ssid = YOUR_WIFI_SSID; +const char *passphrase = YOUR_WIFI_PASSWORD; // Handles our 5 second timer in loop(). unsigned long currentTime = millis(); diff --git a/examples/HelloGrandeur/HelloGrandeur-esp8266/HelloGrandeur-esp8266.ino b/examples/esp8266/HelloGrandeur/HelloGrandeur.ino similarity index 82% rename from examples/HelloGrandeur/HelloGrandeur-esp8266/HelloGrandeur-esp8266.ino rename to examples/esp8266/HelloGrandeur/HelloGrandeur.ino index c1a6a23..3b7b96d 100644 --- a/examples/HelloGrandeur/HelloGrandeur-esp8266/HelloGrandeur-esp8266.ino +++ b/examples/esp8266/HelloGrandeur/HelloGrandeur.ino @@ -1,5 +1,5 @@ /** - * @file HelloGrandeur-esp8266.ino + * @file HelloGrandeur.ino * @date 21.02.2021 * @author Grandeur Technologies * @@ -16,11 +16,11 @@ #include // Device's connection configurations -String apiKey = "YOUR-PROJECT-APIKEY"; -String deviceID = "YOUR-DEVICE-ID"; -String token = "YOUR-ACCESS-TOKEN"; -const char *ssid = "YOUR-WIFI-SSID"; -const char *passphrase = "YOUR-WIFI-PASSWORD"; +String apiKey = YOUR_PROJECT_APIKEY; // Copy from https://console.grandeur.dev/access +String deviceID = YOUR_DEVICE_ID; // Copy your device ID from https://console.grandeur.dev +String token = YOUR_DEVICE_TOKEN; // Copy when you register a new device +const char *ssid = YOUR_WIFI_SSID; +const char *passphrase = YOUR_WIFI_PASSWORD; // Object of Grandeur project. Grandeur::Project project; @@ -56,7 +56,7 @@ void loop() // project.device(deviceID).data().get("state", getStateCallback); - Serial.println("Read the docs at https://github.com/grandeurtech/arduino-sdk."); + Serial.println("Read the docs at https://docs.grandeur.dev/references/device-sdk."); Serial.println("Also checkout other examples: \n- DashListening-Device \n- DashListening-App \n- CrossListening.\n"); } // This runs the SDK only when the WiFi is connected. diff --git a/examples/DashListening-App/DashListening-App-esp8266/DashListening-App-esp8266.ino b/examples/esp8266/MonitorDevice/MonitorDevice.ino similarity index 90% rename from examples/DashListening-App/DashListening-App-esp8266/DashListening-App-esp8266.ino rename to examples/esp8266/MonitorDevice/MonitorDevice.ino index 7c35207..45fc918 100644 --- a/examples/DashListening-App/DashListening-App-esp8266/DashListening-App-esp8266.ino +++ b/examples/esp8266/MonitorDevice/MonitorDevice.ino @@ -1,5 +1,5 @@ /** - * @file DashListening-App-esp8266.ino + * @file MonitorDevice.ino * @date 21.02.2021 * @author Grandeur Technologies * @@ -9,12 +9,11 @@ * Grandeur.h is used for device's communication to Grandeur. * ESP8266WiFi.h is used for handling device's WiFi. * - * Dash listening is for one-way listening. * This example illustrates the use case of an app listening for updates from the device. * It would be useful in building a DEVICE MONITOR which would show how your devices are * behaving in terms of their energy units consumed for example. * - * After uploading this sketch to your ESP, go to https://canvas.grandeur.tech and add + * After uploading this sketch to your ESP, go to your device's canvas and add * a display to monitor the voltage variable. */ @@ -22,11 +21,11 @@ #include // Device's connection configurations: -String apiKey = "YOUR-PROJECT-APIKEY"; -String deviceID = "YOUR-DEVICE-ID"; -String token = "YOUR-ACCESS-TOKEN"; -const char *ssid = "YOUR-WIFI-SSID"; -const char *passphrase = "YOUR-WIFI-PASSWORD"; +String apiKey = YOUR_PROJECT_APIKEY; // Copy from https://console.grandeur.dev/access +String deviceID = YOUR_DEVICE_ID; // Copy your device ID from https://console.grandeur.dev +String token = YOUR_DEVICE_TOKEN; // Copy when you register a new device +const char *ssid = YOUR_WIFI_SSID; +const char *passphrase = YOUR_WIFI_PASSWORD; // Handles our 5 second timer in loop(). unsigned long currentTime = millis(); diff --git a/keywords.txt b/keywords.txt index 9c75cfc..1152b6f 100644 --- a/keywords.txt +++ b/keywords.txt @@ -7,12 +7,11 @@ Grandeur KEYWORD3 grandeur KEYWORD3 Project KEYWORD3 -Datastore KEYWORD3 Device KEYWORD3 -Data KEYWORD3 +Data KEYWORD3 ####################################### -# Datatypes +# Datatypes ####################################### Callback KEYWORD1 @@ -26,22 +25,11 @@ onConnection KEYWORD2 isConnected KEYWORD2 parse KEYWORD2 stringify KEYWORD2 -device KEYWORD2 -datastore KEYWORD2 +device KEYWORD2 loop KEYWORD2 get KEYWORD2 set KEYWORD2 -collection KEYWORD2 -insert KEYWORD2 -remove KEYWORD2 -update KEYWORD2 -search KEYWORD2 -pipeline KEYWORD2 -match KEYWORD2 -project KEYWORD2 -group KEYWORD2 -sort KEYWORD2 -execute KEYWORD2 +on KEYWORD2 ####################################### # Constants diff --git a/library.properties b/library.properties index fd84da6..7d37e89 100644 --- a/library.properties +++ b/library.properties @@ -1,9 +1,9 @@ name=Grandeur -version=1.0.6 +version=1.0.7 author=Grandeur Technologies -maintainer=Grandeur Technologies +maintainer=Grandeur Technologies sentence=Let your arduinos and ESPs communicate with Grandeur in realtime. -paragraph=This handles your realtime connection with Grandeur and exposes devices and datastore APIs. Devices API lets you get, set, and subscribe to device variables. And datastore API lets you query your datastore which is a highly available and scalable NOSQL database for IoT. Visit https://grandeur.tech for more details. +paragraph=This handles your realtime connection with Grandeur and exposes the device API. Device API lets you get, set, and subscribe to device variables. Visit https://grandeur.dev for more details. category=Communication url=https://github.com/grandeurdev/arduino-sdk architectures=* diff --git a/src/Datastore.cpp b/src/Datastore.cpp deleted file mode 100755 index b939894..0000000 --- a/src/Datastore.cpp +++ /dev/null @@ -1,143 +0,0 @@ -/** - * @file Datastore.cpp - * @date 20.06.2020 - * @author Grandeur Technologies - * - * Copyright (c) 2019 Grandeur Technologies LLP. All rights reserved. - * This file is part of the Arduino SDK for Grandeur. - * - */ - -// Including headers -#include "Grandeur.h" - -Grandeur::Project::Datastore::Datastore() {} - -Grandeur::Project::Datastore::Datastore(DuplexHandler* duplexHandler) : _duplex(duplexHandler) {} - -Grandeur::Project::Datastore::Collection Grandeur::Project::Datastore::collection(String name) { - // Return a reference to collection object - return Collection(name, _duplex); -} - -Grandeur::Project::Datastore::Collection::Collection(String name, DuplexHandler* duplexHandler) - : _duplex(duplexHandler), _name(name) {} - -void Grandeur::Project::Datastore::Collection::insert(Var documents, Callback inserted) { - // Insert documents to datastore - Var oPayload; - // Append collection name and documents - oPayload["collection"] = _name; - oPayload["documents"] = documents; - - // Send request to server - _duplex->send("/datastore/insert", oPayload, inserted); -} - -void Grandeur::Project::Datastore::Collection::remove(Var filter, Callback removed) { - // Remove documents from datastore - Var oPayload; - // Append collection name and filter - oPayload["collection"] = _name; - oPayload["filter"] = filter; - - // Send request to server - _duplex->send("/datastore/delete", oPayload, removed); -} - -void Grandeur::Project::Datastore::Collection::update(Var filter, Var update, Callback updated) { - // Update document from datastore - Var oPayload; - // Append collection name, filter and update - oPayload["collection"] = _name; - oPayload["filter"] = filter; - - // Send request to server - _duplex->send("/datastore/update", oPayload, updated); -} - -void Grandeur::Project::Datastore::Collection::search(Var filter, Var projection, int nPage, Callback searched) { - // Basically it will use pipeline - Pipeline searchPipeline = Pipeline(_name, {}, _duplex).match(filter); - - // Add project stage if provided - if(projection == undefined); - else { - searchPipeline = searchPipeline.project(projection); - } - - // Execute the pipeline - return searchPipeline.execute(nPage, searched); -} - -Grandeur::Project::Datastore::Collection::Pipeline Grandeur::Project::Datastore::Collection::pipeline(void) { - // Return a reference to pipeline - return Pipeline(_name, undefined, _duplex); -} - -Grandeur::Project::Datastore::Collection::Pipeline::Pipeline( - String collection, - Var query, - DuplexHandler* duplexHandler -) : _duplex(duplexHandler), _collection(collection), _query(query) {} - -Grandeur::Project::Datastore::Collection::Pipeline Grandeur::Project::Datastore::Collection::Pipeline::match(Var filter) { - // Add match stage to the pipeline - int stage = _query.length() + 1; - - // Add type and filter - _query[stage]["type"] = "match"; - _query[stage]["filter"] = filter; - - // Return reference to pipeline to basically help in chaining - return Pipeline(_collection, _query, _duplex); -} - -Grandeur::Project::Datastore::Collection::Pipeline Grandeur::Project::Datastore::Collection::Pipeline::project(Var specs) { - // Add project stage to the pipeline - int stage = _query.length() + 1; - - // Add type and specs - _query[stage]["type"] = "match"; - _query[stage]["specs"] = specs; - - // Return reference to pipeline to basically help in chaining - return Pipeline(_collection, _query, _duplex); -} - -Grandeur::Project::Datastore::Collection::Pipeline Grandeur::Project::Datastore::Collection::Pipeline::group(Var condition, Var fields) { - // Add group stage to the pipeline - int stage = _query.length() + 1; - - // Add type, condition and fields - _query[stage]["type"] = "match"; - _query[stage]["condition"] = condition; - _query[stage]["fields"] = fields; - - // Return reference to pipeline to basically help in chaining - return Pipeline(_collection, _query, _duplex); -} - -Grandeur::Project::Datastore::Collection::Pipeline Grandeur::Project::Datastore::Collection::Pipeline::sort(Var specs) { - // Add sort stage to the pipeline - int stage = _query.length() + 1; - - // Add type and specs - _query[stage]["type"] = "match"; - _query[stage]["specs"] = specs; - - // Return reference to pipeline to basically help in chaining - return Pipeline(_collection, _query, _duplex); -} - -void Grandeur::Project::Datastore::Collection::Pipeline::execute(int nPage, Callback executed) { - // Define an object - Var oPayload; - // Formulate query - oPayload["collection"] = _collection; - oPayload["pipeline"] = _query; - oPayload["nPage"] = nPage; - - // Send to server - _duplex->send("/datastore/pipeline", oPayload, executed); -} diff --git a/src/DuplexHandler.cpp b/src/DuplexHandler.cpp index bd24ed0..ccc9fca 100755 --- a/src/DuplexHandler.cpp +++ b/src/DuplexHandler.cpp @@ -191,14 +191,6 @@ void DuplexHandler::receive(Var header, Var payload) // Response to Set has data in payload["update"]. else if (strcmp(task, "/device/data/set") == 0) data = payload["update"]; - // For datastore, we delete code and message from the payload and send the rest. - else if (strcmp(task, "/datastore/insert") == 0 || strcmp(task, "/datastore/delete") == 0 || - strcmp(task, "/datastore/update") == 0 || strcmp(task, "/datastore/pipeline") == 0) - { - data = payload; - data["code"] = undefined; - data["message"] = undefined; - } DEBUG_GRANDEUR("Response message:: code: %s, data: %s.", code, JSON.stringify(data).c_str()); diff --git a/src/EventEmitter/EventEmitter.h b/src/EventEmitter/EventEmitter.h index b1d32f1..ace3a4a 100755 --- a/src/EventEmitter/EventEmitter.h +++ b/src/EventEmitter/EventEmitter.h @@ -1,4 +1,5 @@ #include +#include #include "Listener.h" #ifndef _EVENT_EMITTER_H_ diff --git a/src/Grandeur.cpp b/src/Grandeur.cpp index a248ad3..af4191a 100755 --- a/src/Grandeur.cpp +++ b/src/Grandeur.cpp @@ -46,11 +46,6 @@ Grandeur::Project::Device Grandeur::Project::device(String deviceId) { return Device(_duplex, deviceId); } -Grandeur::Project::Datastore Grandeur::Project::datastore(void) { - // Return the new datastore object. - return Datastore(_duplex); -} - void Grandeur::Project::loop(bool valve) { // Running duplex loop. _duplex->loop(valve); diff --git a/src/Grandeur.h b/src/Grandeur.h index e901e20..3f957ac 100755 --- a/src/Grandeur.h +++ b/src/Grandeur.h @@ -38,8 +38,6 @@ class Grandeur::Project { Project(DuplexHandler* duplex); // Class that models a Grandeur device. class Device; - // Class that models datastore. - class Datastore; // Connection related methods: // Schedules a connection handler function to be called on successful connection establishment @@ -52,7 +50,6 @@ class Grandeur::Project { // Instantiator methods — return reference to objects of their classes. Device device(String deviceId); - Datastore datastore(void); // This method runs the SDK. void loop(bool valve); @@ -129,72 +126,6 @@ class Grandeur::Project::Device { Data data(); }; -class Grandeur::Project::Datastore { - private: - // Stores reference to duplex channel we are connected through to Grandeur. - DuplexHandler* _duplex; - - public: - // Constructor - Datastore(); - Datastore(DuplexHandler* duplexHandler); - - // Class that models a datastore collection. - class Collection { - private: - // Stores reference to duplex channel we are connected through to Grandeur. - DuplexHandler* _duplex; - // Stores name of collection - String _name; - - public: - // Constructor - Collection(String name, DuplexHandler* duplexHandler); - - // Inserts documents. - void insert(Var documents, Callback inserted); - // Removes documents matching the filter. - void remove(Var filter, Callback removed); - // Updates documents matching the filter. - void update(Var filter, Var update, Callback updated); - // Performs a search a search on all documents. - void search(Var filter, Var projection, int nPage, Callback searched); - - - // Class that forms a pipeline of datastore collection operations to send them all at once - // to Grandeur. - class Pipeline { - private: - // Stores reference to duplex channel we are connected through to Grandeur. - DuplexHandler* _duplex; - // Stores the collection name - String _collection; - // Stores the whole operations pipeline. - Var _query; - - public: - // Constructor - Pipeline(String collection, Var query, DuplexHandler* duplexHandler); - - // Adds a match stage to pipeline. - Pipeline match(Var filter); - // Add project stage to pipeline. - Pipeline project(Var specs); - // Adds group stage to pipeline. - Pipeline group(Var condition, Var fields); - // Adds sort stage to pipeline. - Pipeline sort(Var specs); - // Execute the query by sending function - void execute(int nPage, Callback executed); - }; - - // Returns a new query pipeline. - Pipeline pipeline(void); - }; - // Gets reference to a particular collection of documents. - Collection collection(String name); -}; - extern Grandeur grandeur; #endif \ No newline at end of file