Send an SMS from an Arduino
Box IO sends text messages through Twilio. The sketch calls BoxIO.sms. The board does not talk to Twilio itself, and the sketch does not contain the auth token.
Save Twilio on the server
- Create a Twilio account and note the Account SID, Auth Token, and a Twilio phone number.
- Sign in as admin at
http://localhostand open Settings. - Under Twilio SMS, set Account SID, Auth token, and From number. The from number looks like
+15551234567. - Click Save settings.
- Type a destination number and click Send test SMS. The page says the test SMS was sent when Twilio accepts it.
Twilio is paid after the trial. It is not required to run the dashboard, the widgets, or email.
Call it from the sketch
BoxIO.sms(to, body) returns true when the server accepts the request. If Twilio is not saved, or the destination or body is empty, the call returns false. Keep BoxIO.run() in loop(). SMS is not counted in the virtualWrite rate cap.
Keep the text short. The library URL-encodes the number into a 40-character buffer and the message into a 140-character buffer. Spaces and punctuation grow when they are encoded, so a long sentence is cut off on the board.
#define BOXIO_AUTH "bx_paste_your_device_key_here"
#define WIFI_SSID "your-ssid"
#define WIFI_PASS "your-password"
#define BOXIO_HOST "localhost"
#define BOXIO_PORT 5923
#include <BoxIOEsp32.h>
void setup() {
BoxIO.begin(BOXIO_AUTH, WIFI_SSID, WIFI_PASS, BOXIO_HOST, BOXIO_PORT);
// Twilio SID, token, and from-number stay in admin Settings.
}
void loop() {
BoxIO.run();
static uint32_t last = 0;
if (millis() - last < 60000) return;
last = millis();
BoxIO.sms("+15551234567", "Pump alarm");
}
What you should see
The test button delivers one text before you flash anything. After the sketch runs, the Twilio from-number sends “Pump alarm” to the number in BoxIO.sms. Use the full number with the country code, the same way the From field is written.