你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

使用来自Seeed Studio的Wio LTE的Twilio M2M命令

[复制链接]
点点&木木 发布时间:2019-3-13 19:50
本帖最后由 点点&木木 于 2019-4-12 22:35 编辑

使用TwilioIoT,Arduino IDE和Seeed Studio Wio LTE发送和接收机器到机器命令。
1.jpg


这个项目中使用的东西
硬件组件
Twilio可编程无线    ×       1      
Seeed Wio LTE US Version - 4G,Cat.1,GNSS,JavaScript(Espruino)兼容 ×    1      
LTE天线     ×    1      
3.7v锂离子电池    ×          1      
USB-A到Micro-USB线       ×     1      

介绍
使用这些说明和SeeedStudio 的Wio LTE,您可以使用Twilio的可编程无线连接到互联网。
我们将在本快速入门中使用ArduinoIDE。虽然我们建议使用Arduino IDE,但代码和说明应该(至少部分地)用于其他C / C ++工作流程。

在本快速入门中,您将学习如何:
·  注册Twilio帐户
·  购买配有3张SIM卡的Twilio Programmable Wireless Starter Pack
·  将SIM卡插入Wio LTE
·  将随附的LTE天线和锂离子电池连接到Wio LTE
·  为Wio LTE供电和闪存
·  使用可编程无线发送和接收机器到机器命令

硬件先决条件
Wio LTE
3.7v锂离子电池,带JST SH 1.0mm 2针连接器
Micro-USB线
LTE蜂窝天线
设置和软件要求
Arduino IDE
Wio LTEArduino图书馆
Wio LTE USB驱动程序(Macintosh / Windows / Linux)
不是你要完成的快速入门?请参阅我们的其他可编程无线快速入门或查看所有无线资源。

注册Twilio帐户并购买SIM卡
已经有Twilio帐户和SIM卡?跳到寄存器并激活步骤。
在您使用Twilio Programmable Wireless连接之前,您需要一个Twilio帐户。注册后,请继续本快速入门。

首先,访问可编程无线控制台。在订单页面上,通过选择SIM卡入门包购买一套3个入门SIM卡...或通过在多尺寸SIM卡产品下输入数量来制作更大的自定义订单。
2.jpg

注意:10张SIM卡或更多SIM卡的订单将与已绑定到您帐户的SIM卡一起发货。

注册,分配费率计划和激活您的SIM
收到SIM卡后,请访问可编程无线控制台中的注册SIM页面
3.jpg

通过为SIM 选择唯一名称来跟进。

选择费率计划
接下来,从Twilio提供的选项中选择费率计划。
默认情况下,添加的费率计划大致相当于Twilio在现场看到的使用情况。利率计划可让您控制设备每月最大数据使用量的各个方面。我们添加了一些合理的默认值,但您可以稍后再探索选项。

激活SIM
如果您对费率计划感到满意,请“激活”SIM卡。
注意:虽然您可以在不激活的情况下使用少量数据,但您需要为实际工作流程激活SIM卡。

将蜂窝天线连接到Wio LTE
由于Wio LTE仍然断电,请从封装中移除LTE天线。将LTE天线连接到Wio上标有“LTE”的连接器。您的设置应如下所示:
4.png

插入SIM

打开Twilio SIM卡并将其插入最靠近Wio上PCB的插槽中。
插槽位于调制解调器侧,并具有方向图。你想把它放在“底部”的插槽中; 上部插槽用于可选的MicroSD卡。
5.jpg

准备连接电池

找到JST连接器并将Lipoly Battery插入电路板。必须始终插入电池才能连接工作。
6.jpg

完成的设置将类似于下图。
7.jpg


安装USB驱动程序
接下来,使用Micro-USB线将Wio LTE连接到计算机。
Wio LTE不需要用于Macintosh的USB驱动程序。有关安装适用于Windows和Linux的Wio LTE USB驱动程序的说明,请参见此处。

安装Wio LTEArduino
在Arduino IDE中,转到Sketch > Include Library > ManageLibraries
8.jpg

使用Library Manager搜索并安装Wio LTE Arduino Library
9.png

安装Seeed STM32F4板

转到Arduino>首选项。
10.jpg

查找其他Boards Manager URL 并粘贴以下JSON URL。
http://raw.githubusercontent.com/Seeed-Studio/Seeed_Platform/master/package_seeeduino_boards_index.json
file:///C:/Users/ADMINI~1/AppData/Local/Temp/msohtmlclip1/01/clip_image022.png

按确定。

转到工具> > 板管理器。
12.jpg

搜索并安装Seeed STM32F4 Boards 包。
13.png


重新启动Arduino IDE
安装了STM32F4内核后,现在可以对Wio LTE进行编程。接下来选择电路板和电路板端口。
单击工具>板> Wio Tracker LTE
14.jpg

单击工具>端口> {您的调制解调器端口}
苹果: /dev/{cu|tty}.usbmodem{XXXX}
Linux的: /dev/ttyACM{X}
视窗: COM{X}
15.jpg

进入Bootloader模式
要将代码上传到Wio LTE,需要将设备置于Bootloader模式
按住Developer Board下方的BOOT0 按钮。
file:///C:/Users/ADMINI~1/AppData/Local/Temp/msohtmlclip1/01/clip_image032.jpg

按住BOOT0 按钮的同时按下RST 按钮一次。
17.jpg

现在,释放BOOT0 按钮进入Bootloader模式。
闪存Wio LTE

您可以直接从Github上的此目录下载代码。
打开文件m2m_command_wiolte.ino。或者,您可以使用“ 文件” >“ 新建草图” 将代码复制/粘贴到新的Arduino草图中。
按“上传”按钮。
18.jpg

可以在代码下方的窗格中查看上载进度。
19.jpg


退出Bootloader模式
上传完成后,按一下RST 按钮退出Bootloader模式。这将启动上传到Wio LTE的新程序。
重启Wio LTE后,在Arduino IDE中打开串行监视器。

工具>串行监视器
串行监视器的输出将如下所示:
20.png

从Wio LTE向Machine命令发送机器
以下是将机器发送到机器命令的方法:
/*
   Twilio Machine to Machine Commands Quickstart for the Seeed Studio Wio LTE
*/
#include "wio_tracker.h"
/*
Globals for receiving incoming Commands
*/
uint16_t newSMSNumber = -1;
char receivedMessage[128];
/*
Create a Wio instance
*/
WioTracker wio = WioTracker();
void setup() {
/*
   Modem setup
*/
wio.Power_On();
SerialUSB.println("Power On!");
SerialUSB.println("Start network registration...");
/*
   Network registration
*/
if (!wio.waitForNetworkRegister())
{
   SerialUSB.println("Network error");
   return;
} else {
   SerialUSB.println("Network registration complete");
}
/*
   Set all "REC UNREAD SMS" to "REC READ SMS"
*/
wio.readAllRecUnreadSMS();
/*
   Keep `command` under 160 ASCII characters, or 67 UCS-2 characters.
   http://www.twilio.com/docs/glossary/what-sms-character-limit
*/
SerialUSB.println("Sending Command");
char message[128] = "Hello from the Wio LTE!";
/*
   Send an SMS to short code 2936, which is a Twilio
   Machine-to-Machine command.
   Write a Twilio M2M command. */
if (wio.sendSMS("2936", message))
{
   SerialUSB.println("Command Sent");
}
else
{
   SerialUSB.println("Send Error");
} SerialUSB.println("Waiting for Command");}

成功发送命令后,串行监视器中将显示一条消息:
21.png


验证已发送机器到机器命令
检查命令成功的最简单方法是通过可编程无线控制台。
从控制台中,从可编程无线菜单中选择SIM
单击您正在用于此项目的SIM,然后导航到“ 命令” 选项卡。

复制SIM Sid
正如您可能猜到的那样,我们将实施反向 - 您将在使用SIM的Sid进行API调用触发的Wio LTE上收到2936 的入站短信。让我们看看下一步。
22.jpg

使用Wio LTE接收机器到机器命令
同样,我们已经包含了帮助您轻松接收M2M命令的代码。
void loop() {
/*
   Detect unread Commands
*/
int id = wio.detectRecUnreadSMS();
/*
   Define the index of the incoming Commands
*/
if (-1 != id) {
   newSMSNumber = id;
   /*
     Read a Twilio M2M command. Note that it will find the lowest
     indexed one with the code as is; in your code. if you cache the
     index you can start the next read_command to move to the next one.
   */
   wio.readSMS(newSMSNumber, receivedMessage, 128);
   SerialUSB.println("Command Received");
   SerialUSB.println(receivedMessage);
}
delay(1000);
}
要测试它,请返回Arduino IDE并确保串行监视器仍然连接。响应命令的最快方法是使用cURL(如果可用)。
如果可以,使用cURL将命令(160个ASCII字符以下)发送回SIM卡:
如果一切顺利,Wio LTE将接收命令,您应该看到成功运行:
curl -X POST http://wireless.twilio.com/v1/Commands -d 'Sim=DEXXXXXXXXXXXXXXXXXXXXXXXXXXXX' -d 'Command=Hello from cURL!' -u 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXX:YOUR_API_KEY'

23.png


这就是使用Wio LTE进行机器到机器命令的全部内容。您现在知道如何将机器命令发送到机器并在控制台中检查它们的状态。您还可以从您的计算机返回命令,并了解如何使用Wio LTE接收它。

有了这些基本构建模块,您就可以构建下一个大型IoT Thing了!

完整代码:
/*
   Twilio Machine to Machine Commands Quickstart for the Seeed Studio Wio LTE
*/
#include "wio_tracker.h"
/*
Globals for receiving incoming Commands
*/
uint16_t newSMSNumber = -1;
char receivedMessage[128];
/*
Create a Wio instance
*/
WioTracker wio = WioTracker();
void setup() {
/*
   Modem setup
*/
wio.Power_On();
SerialUSB.println("Power On!");
SerialUSB.println("Start network registration...");
/*
   Network registration
*/
if (!wio.waitForNetworkRegister())
{
   SerialUSB.println("Network error");
   return; } else {   SerialUSB.println("Network registration complete"); } /*
   Set all "REC UNREAD SMS" to "REC READ SMS"
*/
wio.readAllRecUnreadSMS();
/*
   Keep `command` under 160 ASCII characters, or 67 UCS-2 characters.
   http://www.twilio.com/docs/glossary/what-sms-character-limit
*/
SerialUSB.println("Sending Command");
char message[128] = "Hello from the Wio LTE!";
/*
   Send an SMS to short code 2936, which is a Twilio
   Machine-to-Machine command.
   Write a Twilio M2M command.
*/
if (wio.sendSMS("2936", message))
{
   SerialUSB.println("Command Sent");
}
else
{
   SerialUSB.println("Send Error");
}
SerialUSB.println("Waiting for Command");
}
void loop() {
/*
   Detect unread Commands
*/
int id = wio.detectRecUnreadSMS();
/*
   Define the index of the incoming Commands
*/
if (-1 != id) {
   newSMSNumber = id;
   /*
     Read a Twilio M2M command. Note that it will find the lowest
     indexed one with the code as is; in your code. if you cache the
     index you can start the next read_command to move to the next one.
   */
   wio.readSMS(newSMSNumber, receivedMessage, 128);
   SerialUSB.println("Command Received");
   SerialUSB.println(receivedMessage);
}
delay(1000);
}

现在您已经了解了如何使用Wio LTE和开发机器发送和接收机器命令到机器,您已准备好构建您的第一个TwilioIoT项目。以下是一些可能的想法,将其提升到一个新的水平:
使用TwilioWireless Blueprints尝试完整的端到端应用程序
深入研究可编程无线API
查看所有可编程无线指南和教程
用#TwilioIoT对我的奶奶说生日快乐


需要一些帮助?
我们有时都这样做; 代码很难。立即从我们的支持团队获取帮助,或依靠人群的智慧浏览Stack Overflow上的Twilio标签

原理图
Wio LTE硬件设置

24.png



代码
/*
   Twilio Machine to Machine Commands Quickstart for the Seeed Studio Wio LTE
*/
#include "wio_tracker.h"

/*
Globals for receiving incoming Commands
*/
uint16_t newSMSNumber = -1;
char receivedMessage[128];

/*
Create a Wio instance
*/
WioTracker wio = WioTracker();

void setup() {
  /*
   Modem setup
  */
wio.Power_On();
SerialUSB.println("Power On!");
SerialUSB.println("Start network registration...");

  /*
   Network registration
  */
  if (!wio.waitForNetworkRegister())
  {
   SerialUSB.println("Network error");
    return;
  } else {
   SerialUSB.println("Network registration complete");
  }

  /*
   Set all "REC UNREAD SMS" to "REC READSMS"
  */
wio.readAllRecUnreadSMS();

  /*
   Keep `command` under 160 ASCII characters, or 67 UCS-2 characters.
  */
SerialUSB.println("Sending Command");
char message[128] = "Hello from the Wio LTE!";

  /*
   Send an SMS to short code 2936, which is a Twilio
   Machine-to-Machine command.

   Write a Twilio M2M command.
  */
  if (wio.sendSMS("2936", message))
  {
   SerialUSB.println("Command Sent");
  }
  else
  {
   SerialUSB.println("Send Error");
  }
SerialUSB.println("Waiting for Command");
}

void loop() {
  /*
   Detect unread Commands
  */
  intid =wio.detectRecUnreadSMS();

  /*
   Define the index of the incoming Commands
  */
  if (-1 != id) {
    newSMSNumber = id;

   /*
     Read a Twilio M2M command. Note that it will find the lowest
     indexed one with the code as is; in your code. if you cache the
     index you can start the next read_command to move to the next one.
   */
   wio.readSMS(newSMSNumber, receivedMessage, 128);
   SerialUSB.println("Command Received");
   SerialUSB.println(receivedMessage);
  }
delay(1000);
}


相关文件
Seeed-Studio / Wio_LTE_Arduino_Library--- Wio_LTE_Arduino_Library-master.zip (108.69 KB, 下载次数: 0)
11.png
16.jpg
收藏 评论0 发布时间:2019-3-13 19:50

举报

0个回答

所属标签

STM32团队

意法半导体微控制器和微处理器拥有广泛的产品线,包含低成本的8位单片机和基于ARM® Cortex®-M0、M0+、M3、M4、M33、M7及A7内核并具备丰富外设选择的32位微控制器及微处理器


最新内容

关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
STM32N6 AI生态系统
STM32MCU,MPU高性能GUI
ST ACEPACK电源模块
意法半导体生物传感器
STM32Cube扩展软件包
关注我们
st-img 微信公众号
st-img 手机版