基于 Sigfox 与 Twilio 的远程短信按钮:Arduino MKR Fox 1200 实现
组件与物料
| 组件 | 数量 |
|---|---|
| Arduino MKR Fox 1200 | 1 |
| 大型按钮开关 | 1 |
| LiPo 电池或 2节 AA/AAA 电池 | 1 |
| 按键开关 | 1 |
| thethings.io 贴纸(装饰) | 1 |
应用与在线服务
- Sigfox 物联网网络
- Twilio SMS Messaging API
项目简介
受特朗普“可乐按钮”启发,我们利用 Sigfox 低功耗广域网络和 Twilio 短信 API,制作一个按下即发送短信的物理按钮。适合老人呼叫、紧急求助、趣味恶作剧等场景。
什么是 Sigfox?
Sigfox 提供全球覆盖、低功耗、低成本的物联网网络,已在 32 个国家部署。适合传输小数据量、长距离、双向通信的 IoT 应用。
硬件连接
按键开关连接 Arduino 引脚 7 和 GND。常闭触点,按下时断开。代码中可反转逻辑。
Arduino 代码核心逻辑
#include <SigFox.h>
#include <ArduinoLowPower.h>
const uint8_t SWITCH_PIN = 7;
const String payload = "COKE NOW!";
const uint8_t debug = false;
void setup() {
if (debug) { Serial.begin(9600); while (!Serial); }
if (!SigFox.begin()) { Serial.println("Shield error!"); return; }
SigFox.end(); // 进入深度睡眠
pinMode(SWITCH_PIN, INPUT_PULLUP);
LowPower.attachInterruptWakeup(SWITCH_PIN, buttonPressed, RISING);
}
void loop() {
LowPower.sleep(); // 等待中断唤醒
Serial.println("Button pushed!");
delay(100);
sendString(payload);
}
void sendString(String str) {
SigFox.begin();
delay(100);
SigFox.status();
delay(1);
SigFox.beginPacket();
SigFox.print(str);
int ret = SigFox.endPacket();
if (ret > 0) Serial.println("No transmission");
else Serial.println("Transmission ok");
SigFox.end();
}
void buttonPressed() { /* 中断服务程序,仅唤醒 */ }
Twilio 配置
- 免费注册 Twilio 账号
- 在“Verified Caller IDs”添加接收短信的手机号
- 记下 Twilio 分配的电话号码、Account SID 和 Auth Token
Sigfox 回调配置
在 Sigfox 后端创建自定义回调:
- Type:
DATA UPLINK - Channel:
URL - URL pattern:
https://[AccountSID]:[AuthToken]@api.twilio.com/2010-04-01/Accounts/[AccountSID]/Messages.json - HTTP Method:
POST - Content-Type:
application/x-www-form-urlencoded - Body:
From=[YourTwilioNumber]&To=[TargetNumber]&Body=covfefe!
每次按下按钮,Sigfox 收到数据后触发回调,Twilio 发送短信“covfefe!”到目标手机。
验证测试
用力按下按钮,等待管家送饮料!(或收到短信通知)
代码仓库
GitHub: https://github.com/aureleq/TrumpButton
制造工艺
- 纽扣:从古老扣件到现代创新
- Arduino Mega 按键 PWM 调光:三阶段渐变 LED 实战教程
- Arduino Nano高速摄影控制器 – 定格水滴碰撞瞬间
- Giftduino:面向极客与教育者的终极 Arduino 礼物盒
- 自制可拳击的可编程键盘按钮:基于 Arduino 与压电元件的分步指南
- 用 Arduino 测量地球质量:DIY 分步指南
- MAX30100脉搏血氧传感器与Arduino接入指南:获取PPG波形与SpO2
- 使用 Nextion 显示屏构建 Fridgeye 应用:分步指南
- 分步指南:将 YL-39/YL-69 土壤湿度传感器连接到 Arduino UNO
- 基于 Arduino UNO 与 ThingShield 的 SmartThings 红外网关
- Health Band 智能健康手环:基于 Infineon DPS310 的老人跌倒/步数/体温监护系统
- Sigfox 推出专用区域网络,增强地理定位,拓展物联网解决方案