首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何发送带有Esp8266 Sparkfun Wifi盾和Arduino的短信?

如何发送带有Esp8266 Sparkfun Wifi盾和Arduino的短信?
EN

Stack Overflow用户
提问于 2016-07-20 02:39:53
回答 1查看 994关注 0票数 0

我目前正在尝试通过Arduino Uno使用Sparkfun esp2866无线盾牌发送一条消息。我已经建立了Twilio和Temboo帐户。使用Temboo和Sparkfun esp2866屏蔽库,我已经生成了下面的代码,其中提取了我所有的个人信息。

我没有在我的代码中包含另一个文件,它包含了我所有的Temboo帐户信息。

当我尝试运行该程序时,屏蔽程序连接到我的wifi网络,但它不会将文本消息发送到我的手机上。我没有太多使用物联网设备的经验,我想知道是否有人可以帮助我。感谢您的任何意见!

提前谢谢你!

代码语言:javascript
复制
#include <SoftwareSerial.h> 
#include <SparkFunESP8266WiFi.h>
#include <Temboo.h>
#include "TembooAccount.h" 

const char mySSID[] = "ssid ";
const char myPSK[] = " password";

ESP8266Client client;


int numRuns = 1;   // Execution count, so this doesn't run forever
int maxRuns = 10; 

void setup() 
{
  // Serial Monitor is used to control the demo and view
  // debug information.
  Serial.begin(9600);
  Serial.println("Serial started");
  serialTrigger(F("Press any key to begin."));

  // initializeESP8266() verifies communication with the WiFi
  // shield, and sets it up.
  initializeESP8266();

  // connectESP8266() connects to the defined WiFi network.
  connectESP8266();

  // displayConnectInfo prints the Shield's local IP
  // and the network it's connected to.
  displayConnectInfo();


}

void loop() 
{
    if (numRuns <= maxRuns) {
    Serial.println("Running SendSMS - Run #" + String(numRuns++));
    delay(1000);
    TembooChoreo SendSMSChoreo(client);

    // Invoke the Temboo client
    SendSMSChoreo.begin();

    // Set Temboo account credentials
    SendSMSChoreo.setAccountName(TEMBOO_ACCOUNT);
    SendSMSChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
    SendSMSChoreo.setAppKey(TEMBOO_APP_KEY);

    // Set Choreo inputs
    String AuthTokenValue = "";
    SendSMSChoreo.addInput("AuthToken", AuthTokenValue);
    String ToValue = "";
    SendSMSChoreo.addInput("To", ToValue);
    String FromValue = "";
    SendSMSChoreo.addInput("From", FromValue);
    String BodyValue = "Hello World";
    SendSMSChoreo.addInput("Body", BodyValue);
    String AccountSIDValue = "";
    SendSMSChoreo.addInput("AccountSID", AccountSIDValue);

    // Identify the Choreo to run
    SendSMSChoreo.setChoreo("/Library/Twilio/SMSMessages/SendSMS");

    // Run the Choreo; when results are available, print them to serial
    SendSMSChoreo.run();
    Serial.println("DONE!");
    while(SendSMSChoreo.available()) {
      char c = SendSMSChoreo.read();
      Serial.print(c);
    }
    SendSMSChoreo.close();
  }

  Serial.println("\nWaiting...\n");
  delay(30000); // wait 30 seconds between SendSMS calls
}


void initializeESP8266()
{
  // esp8266.begin() verifies that the ESP8266 is operational
  // and sets it up for the rest of the sketch.
  // It returns either true or false -- indicating whether
  // communication was successul or not.
  // true
  int test = esp8266.begin();
  if (test != true)
  {
    Serial.println(F("Error talking to ESP8266."));
    errorLoop(test);
  }
  Serial.println(F("ESP8266 Shield Present"));
}

void connectESP8266()
{
  // The ESP8266 can be set to one of three modes:
  //  1 - ESP8266_MODE_STA - Station only
  //  2 - ESP8266_MODE_AP - Access point only
  //  3 - ESP8266_MODE_STAAP - Station/AP combo
  // Use esp8266.getMode() to check which mode it's in:
  int retVal = esp8266.getMode();
  if (retVal != ESP8266_MODE_STA)
  { // If it's not in station mode.
    // Use esp8266.setMode([mode]) to set it to a specified
    // mode.
    retVal = esp8266.setMode(ESP8266_MODE_STA);
    if (retVal < 0)
    {
      Serial.println(F("Error setting mode."));
      errorLoop(retVal);
    }
  }
  Serial.println(F("Mode set to station"));

  // esp8266.status() indicates the ESP8266's WiFi connect
  // status.
  // A return value of 1 indicates the device is already
  // connected. 0 indicates disconnected. (Negative values
  // equate to communication errors.)
  retVal = esp8266.status();
  if (retVal <= 0)
  {
    Serial.print(F("Connecting to "));
    Serial.println(mySSID);
    // esp8266.connect([ssid], [psk]) connects the ESP8266
    // to a network.
    // On success the connect function returns a value >0
    // On fail, the function will either return:
    //  -1: TIMEOUT - The library has a set 30s timeout
    //  -3: FAIL - Couldn't connect to network.
    retVal = esp8266.connect(mySSID, myPSK);
    if (retVal < 0)
    {
      Serial.println(F("Error connecting"));
      errorLoop(retVal);
    }
  }
}

void displayConnectInfo()
{
  char connectedSSID[24];
  memset(connectedSSID, 0, 24);
  // esp8266.getAP() can be used to check which AP the
  // ESP8266 is connected to. It returns an error code.
  // The connected AP is returned by reference as a parameter.
  int retVal = esp8266.getAP(connectedSSID);
  if (retVal > 0)
  {
    Serial.print(F("Connected to: "));
    Serial.println(connectedSSID);
  }

  // esp8266.localIP returns an IPAddress variable with the
  // ESP8266's current local IP address.
  IPAddress myIP = esp8266.localIP();
  Serial.print(F("My IP: ")); Serial.println(myIP);
}



// errorLoop prints an error code, then loops forever.
void errorLoop(int error)
{
  Serial.print(F("Error: ")); Serial.println(error);
  Serial.println(F("Looping forever."));
  for (;;)
    ;
}

// serialTrigger prints a message, then waits for something
// to come in from the serial port.
void serialTrigger(String message)
{
  Serial.println();
  Serial.println(message);
  Serial.println();
  while (!Serial.available())
    ;
  while (Serial.available())
    Serial.read();
}
EN

回答 1

Stack Overflow用户

发布于 2016-07-20 22:35:26

我在Temboo工作。

虽然我们没有正式支持ESP8266,但我们找到了一些论坛帖子,在这些帖子中,人们能够让Temboo与ESP8266一起工作。这就是了:

http://www.esp8266.com/viewtopic.php?p=24019

https://forum.arduino.cc/index.php?topic=337186.0

如果这还不能解决问题,请随时联系Temboo Support,我们将尽最大努力帮助您找出问题所在。

您需要注意的一条关键信息是,您需要修改以下Temboo库文件:

代码语言:javascript
复制
\Arduino\libraries\Temboo\src\Temboo.cpp

\Arduino\libraries\Temboo\src\utility\
--ChoreoInputFormatter
--ChoreoOutputFormatter
--ChoreoPresetFormatter
--TembooSession
--tmbhmac
--tmbmd5

您需要修改这些文件中出现的所有"avr/pgmspace.h“,将其更改为”pgmspace.h“。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38466153

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档