Send Notifications with Arduino

Learn how to send push notifications from your Arduino(ESP32 board).

Pushinator is a powerful push notification service that lets you send real-time updates to iPhone, iPad, and Android devices. This guide explains how to use Pushinator with Arduino.

1

Set up your notification channel and devices

First, log in to the Pushinator Console and create a channel (e.g., "Smart Greenhouse Alpha"). Save Channel ID, obtain an API token and save it for later use too.


Install the Pushinator app from the App Store or Google Play on your devices. Use the app to scan your channel’s QR code and subscribe your devices to notifications.

2

Required Libraries

Ensure you have the following libraries installed in your Arduino IDE:

  • - WiFi (built-in for ESP32
  • - HTTPClient (built-in for ESP32)
  • - ArduinoJson (by Benoit Blanchon)
3

Send a notification

Use the following code to connect to WiFi and send a push notification. Replace placeholders with your actual credentials.

Configuration

#include <WiFi.h>
#include <WiFiClientSecure.h>
#include <HTTPClient.h>
#include <ArduinoJson.h>
            
const char* ssid     = "YOUR_WIFI_SSID";
const char* password = "YOUR_WIFI_PASSWORD";
            
// Pushinator credentials
const char* apiToken  = "YOUR_ACCOUNT_API_TOKEN";
const char* channelId = "YOUR_CHANNEL_ID";

TLS Setup

WiFiClientSecure client;

// For tutorials and testing only.
// In production, use a Root CA certificate.
void setupTLS() {
    client.setInsecure();
}

Sending a Push Notification

void sendPush(const char* message, bool requireAck = false) {

    if (WiFi.status() != WL_CONNECTED) {
        Serial.println("WiFi not connected");
        return;
    }

    HTTPClient http;

    setupTLS();
    http.begin(client, "https://api.pushinator.com/api/v2/notifications/send");

    http.addHeader("Content-Type", "application/json");
    http.addHeader("Authorization", String("Bearer ") + apiToken);

    StaticJsonDocument<256> doc;
    doc["channel_id"] = channelId;
    doc["content"] = message;
    doc["acknowledgment_required"] = requireAck;

    String payload;
    serializeJson(doc, payload);

    int status = http.POST(payload);

    if (status > 0) {
        Serial.printf("Push sent, HTTP status: %d\n", status);
    } else {
        Serial.printf("Push failed: %s\n",
                      http.errorToString(status).c_str());
    }

    http.end();
}

Setup and First Notification

void setup() {
    Serial.begin(115200);

    WiFi.begin(ssid, password);

    unsigned long start = millis();
    while (WiFi.status() != WL_CONNECTED && millis() - start < 10000) {
        delay(500);
        Serial.print(".");
    }

    if (WiFi.status() == WL_CONNECTED) {
        Serial.println("\nWiFi connected");
        sendPush("ESP32 online: monitoring started", false);
    } else {
        Serial.println("\nWiFi connection failed");
    }
}

void loop() {}

Need help?

Drop us a message at [email protected], and we will try our best to assist you. Feel free to request a feature or integration, or let us know if there are any issues on our side.