This arduino sample code shows how to use ESP32 and Pushsafer. It is often necessary to be immediately aware of the condition of our appliances, eg when the temperature of the refrigerator rises, etc.
Things used:
First, we need to register a free account on pushsafer.com. Once registered, you will receive 1000 API calls as a gift, which is enough for many things. Once used, you can buy another 1000 API calls for 0.99€.
Download the app from your device’s store.
Log in with your pushsafer credentials, register your device following the instructions in the app.
Download the Pushsafer library, then unpack it in Arduino/libraries/. Restart the Arduino IDE.
Copy this code into the editor, enter the Wifi connection details. Login to pushsafer.com, copy the Pushsafer private key and the Device ID of the device you want to send the messages to into your draft.
The Pushsafer private key and device ID can be found here.
Once that’s done, upload it to ESP32.
/**************************************/
// https://myhomethings.eu //
// ESP32 Module //
// Pushsafer Test //
/**************************************/
#include <WiFi.h>
#include <WiFiClient.h>
#include <Pushsafer.h>
#define PushsaferKey "Private Key" // Private Key from: http://pushsafer.com
char ssid[] = "Wifi_SSID";
char password[] = "SuperSecretWifiPassword";
WiFiClient client;
Pushsafer pushsafer(PushsaferKey, client);
void setup()
{
WiFi.mode(WIFI_STA);
delay(100);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
}
// This can also go into the loop subject to some condition:
struct PushSaferInput input;
input.message = "Test message from ESP32";
input.title = "Hi!";
input.sound = "6";
input.vibration = "1";
input.icon = "1";
input.iconcolor = "#00FF00";
input.priority = "1";
input.device = "xxxxx"; // Device ID: http://pushsafer.com
pushsafer.sendEvent(input);
}
void loop()
{
}
myQ Chamberlain Smart Garage Control
advertising
How to work the code
The necessary libraries are added at the beginning of the outline.
#include <WiFi.h>
#include <WiFiClient.h>
#include <Pushsafer.h>
For the PushsaferKey constant, we assign the pushsafer private key, which is found in our pushsafer account.
#define PushsaferKey "Privát_Kulcs"
Enter the SSID/password pair required to connect to the wifi.
const char ssid[] = "Wifi_SSID";
const char password[] = "SzupertitkosWifiJelszó";
Create an instance of the WiFiClient and Pushsafer classes.
WiFiClient client;
Pushsafer pushsafer(PushsaferKey, client);
Connect to the wifi network…
WiFi.mode(WIFI_STA);
delay(100);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
}
Then we create a structure, compose the pushsafer message and send it to the specified device. Don’t forget to select the Device ID from your pushsafer account.
struct PushSaferInput input;
input.message = "Test message from ESP32";
input.title = "Hi!";
input.sound = "6";
input.vibration = "1";
input.icon = "1";
input.iconcolor = "#00FF00";
input.priority = "1";
input.device = "xxxxx"; // Device ID: http://pushsafer.com
pushsafer.sendEvent(input);
This example can also be used for ESP8266. Let’s see the following example:
/**************************************/
// https://myhomethings.eu //
// NodeMCU ESP8266 Module //
// Pushsafer Test //
/**************************************/
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <Pushsafer.h>
#define PushsaferKey "Private Key" // Private Key: http://pushsafer.com
char ssid[] = "Wifi_SSID";
char password[] = "SuperSecretWifiPassword";
WiFiClient client;
Pushsafer pushsafer(PushsaferKey, client);
void setup()
{
WiFi.mode(WIFI_STA);
delay(100);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
}
// This can also go into the loop subject to some condition:
struct PushSaferInput input;
input.message = "Test message from ESP32";
input.title = "Hi!";
input.sound = "6";
input.vibration = "1";
input.icon = "1";
input.iconcolor = "#00FF00";
input.priority = "1";
input.device = "xxxxx"; // Device ID: http://pushsafer.com
pushsafer.sendEvent(input);
}
void loop()
{
}
This is just an example, but can be easily integrated into your own application. It is so easy to send an instant notification about ESP32 using Pushsafer.
Here are some more interesting things
SparkFun ESP32 WROOM with ESP32-D0WDQ6 chip
Xtensa dual-core 32-bit LX6 microprocessor Up to 240MHz clock frequency, Integrated 802.11 BGN WiFi, 21 GPIO 8-electrode capacitive touch support
advertising