Rene Brakus
Published © GPL3+

How to enable an ESP32-PICO to send SMS (IOT)

Detailed tutorial on how to enable your ESP32 to send SMS

IntermediateFull instructions provided30 minutes3,370
How to enable an ESP32-PICO to send SMS (IOT)

Things used in this project

Hardware components

M5StickC ESP32-PICO Mini IoT Development Board
M5Stack M5StickC ESP32-PICO Mini IoT Development Board
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Code

Code snippet #9

Plain text
#include < M5StickC.h >
#include < Arduino.h >
#include < WiFi.h >
#include < WiFiMulti.h >

#include < HTTPClient.h >
#define USE_SERIAL Serial
WiFiMulti wifiMulti;

void setup() {
    USE_SERIAL.begin(115200);
    USE_SERIAL.println();
    USE_SERIAL.println();
    USE_SERIAL.println();
    for(uint8_t t = 4; t > 0; t--) {
        USE_SERIAL.printf("[SETUP] WAIT %d...\n", t);
        USE_SERIAL.flush();
        delay(1000);
    }
    wifiMulti.addAP("sonoff", "sonoff*11");
// add your Wifi 
}
void loop() {
    // waiting for WiFi connection
    if((wifiMulti.run() == WL_CONNECTED)) {

        HTTPClient http;

        USE_SERIAL.print("[HTTP] begin...\n");
        // configure  server and url
          http.begin("https://api.46elks.com/a1/sms");
          http.addHeader("Content-Type", "application/x-www-form-urlencoded"); 
          http.setAuthorization("ae7d33d5b324edc91cb8e61f35c18e02d", "3A925F02297D0B10835ADE2B59FC580C");
          int httpCode = http.POST("from=ESP32&to=+385996768133&message=This is working!");

        USE_SERIAL.print("[HTTP] GET...\n");
        // start connection and send HTTP header
         httpCode = http.GET();

        // httpCode will be negative on error
        if(httpCode > 0) {
            // HTTP header has been send and Server response header has been handled
            USE_SERIAL.printf("[HTTP] GET... code: %d\n", httpCode);

            // file found at server
            if(httpCode == HTTP_CODE_OK) {
                String payload = http.getString();
                USE_SERIAL.println(payload);
            }
        } else {
            USE_SERIAL.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
        }

        http.end();
    }
while(1){};
// while loop was put here in order for the code to be run once
// and the reason why you get one SMS
}

Code snippet #10

Plain text
#include < M5StickC.h >
#include < Arduino.h >
#include < WiFi.h >
#include < WiFiMulti.h >

#include < HTTPClient.h >
#define USE_SERIAL Serial
WiFiMulti wifiMulti;

void setup() {
    USE_SERIAL.begin(115200);
    USE_SERIAL.println();
    USE_SERIAL.println();
    USE_SERIAL.println();
    for(uint8_t t = 4; t > 0; t--) {
        USE_SERIAL.printf("[SETUP] WAIT %d...\n", t);
        USE_SERIAL.flush();
        delay(1000);
    }
    wifiMulti.addAP("sonoff", "sonoff*11");
// add your Wifi 
}
void loop() {
    // waiting for WiFi connection
    if((wifiMulti.run() == WL_CONNECTED)) {

        HTTPClient http;

        USE_SERIAL.print("[HTTP] begin...\n");
        // configure  server and url
          http.begin("https://api.46elks.com/a1/sms");
          http.addHeader("Content-Type", "application/x-www-form-urlencoded"); 
          http.setAuthorization("ae7d33d5b324edc91cb8e61f35c18e02d", "3A925F02297D0B10835ADE2B59FC580C");
          int httpCode = http.POST("from=ESP32&to=+385996768133&message=This is working!");

        USE_SERIAL.print("[HTTP] GET...\n");
        // start connection and send HTTP header
         httpCode = http.GET();

        // httpCode will be negative on error
        if(httpCode > 0) {
            // HTTP header has been send and Server response header has been handled
            USE_SERIAL.printf("[HTTP] GET... code: %d\n", httpCode);

            // file found at server
            if(httpCode == HTTP_CODE_OK) {
                String payload = http.getString();
                USE_SERIAL.println(payload);
            }
        } else {
            USE_SERIAL.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
        }

        http.end();
    }
while(1){};
// while loop was put here in order for the code to be run once
// and the reason why you get one SMS
}

Credits

Rene Brakus

Rene Brakus

1 project • 0 followers
Thanks to Ben Chatwin.

Comments