Intel Edison و Arduino و Twilio: رسائل SMS للمنزل الذكي

Intel Edison – , , , , . – , Arduino. ++, Intel Edison – , (sketch) Arduino. , Intel Edison . . Intel Edison , , .

Twilio SMS MMS- Twilio, , , . SMS MMS- , REST API Twilio, SMS- SMS- . SMS- Twilio.

, SMS- , Twilio.


, SMS-, :

  • Intel Edison
  • Arduino
  • Grove – Starter Kit Plus
  • Micro USB-

, Intel Edison, .





Intel Edison Board Software Downloads , , , IDE Arduino.

Twilio


Twilio C++ Arduino IDE, C:\Arduino\arduino-1.5.3-Intel.1.0.4\libraries. Arduino , «–», twilio-cplusplus Twilio.


Twilio

Twilio Example.cpp Example.cpp.org, Example.cpp , Twilio. Utils.h :

Utils.h

#include <string.h>
#include <vector>

using namespace std;

USB Mass Storage Intel Edison


Multifunction Composite Gadget (g_multi) – , composite framework . , USB- USB Mass Storage, – Ethernet (RNDIS () CDC Ethernet) (ACM).

, modprobe. g_multi , USB Mass Storage Intel Edison.


modprobe, Edison

.


, Edison

losetup , «update» loopback (/dev/loop0) 8192. , , loopback /mnt/transfer.


Edison

USB Mass Storage


, USB Mass Storage Windows.


USB Mass Storage

g_multi.




Curl


« USB Mass Storage Intel Edison» , libcurl /usr/lib Edison Arduino IDE, hardware\tools\edison\sysroots\core2-32-poky-linux\usr\lib:

  • libcurl.so
  • libtasn1.so.6
  • libgcrypt.so.11
  • libgnutls.so.26
  • libgpg-error.so.0


Curl Edison


Curl Windows

, « USB Mass Storage Intel Edison» , /lib Edison Arduino IDE, hardware\tools\edison\sysroots\core2-32-poky-linux\lib:

  • libz.so.1
  • libcap.so.2
  • libcrypto.so


Edison


Windows

Curl


Curl Arduino IDE hardware\tools\edison\sysroots\core2-32-poky-linux\usr\include:


Curl

OpenSSL Arduino IDE hardware\tools\edison\sysroots\core2-32-poky-linux\usr\include:


OpenSSL


Arduino IDE, hardware\arduino\edison, platform.*.txt. , , . Arduino IDE Microsoft Windows, platform.win.txt.


platform.win.txt Windows

, libcurl libcrypto , –lcurl –lcrypto «recipe.c.combine.pattern». .

– platform.win.txt.

recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" {compiler.c.elf.flags} -march={build.mcu} -o "{build.path}/{build.project_name}.elf" {object_files} "{build.path}/{archive_file}" "-L{build.path}" -lm -lpthread -lcurl –lcrypto


Twilio


SMS MMS- Twilio, SMS. , Twilio. , Hide API Credentials Twilio Account SID Auth Token:

Twilio

//  Twilio REST API 
const char API_VERSION[] = "2010-04-01";

//   Twilio   SMS
const char CALLER_ID[] = "1480405xxxx";

// Account SID  Auth token     Twilio
const char ACCOUNT_SID[] = "AC9c55339a5a070ae81e782117xxxxxxxx";
const char ACCOUNT_TOKEN[] = "59e8819f3f5b530b97b84baexxxxxxxx";


POST- Twilio


SMS-, POST- Twilio, URL «/SMS/Messages». «To», «From» «Body». «To» — , , SMS. «From» — Twilio, «Body» — SMS-.

SMS Twilio

// URL path = /API_VERSION/Accounts/ACCOUNT_SID/SMS/Messages
char postReqStr[150];
strcpy(postReqStr, twilioAcc);
strcat(postReqStr, "/SMS/Messages");
Serial.println(postReqStr);

//  SMS
vars.clear();
vars.push_back(Var("To", "480-xxx-xxxx"));
vars.push_back(Var("From", "480-405-xxxx"));
vars.push_back(Var("Body", smsStr));
string response = twilioRest.request(postReqStr, "POST", vars);



, SMS-, . , . . .



//       1
const int tempSensorPin = 1;

//   
float degF = 0;

//       ,  
//        .
float getTemperature()
{
    int analogValue = analogRead(tempSensorPin);
  
    //   ;
    float resistance = (float)(1023 - analogValue) * 10000/analogValue;
 
    //       ; 
    float degKelvin = 1/(log(resistance/10000)/B_THERMISTOR + 1/298.15);
  
    //       
    float degC = degKelvin - 273.15;
  
    //       
    degF = (degC * 9.0) / 5.0 + 32.0;
        
    return degF;
}


SMS- , 100 . Galileo Arduino IDE.

SMS Twilio

#include "WString.h"
#include <Utils.h>
#include <Rest.h>
#include <TwiML.h>
#include <vector>
#include <math.h>

using namespace twilio;

vector<Var> vars;

//  Twilio REST API 
const char API_VERSION[] = "2010-04-01";

//   Twilio   SMS
const char CALLER_ID[] = "1480405xxxx";

// Account SID  Auth token     Twilio
const char ACCOUNT_SID[] = " AC9c55339a5a070ae81e782117xxxxxxxx ";
const char ACCOUNT_TOKEN[] = "59e8819f3f5b530b97b84baexxxxxxxx ";

//   Twilio
const char* responseStr;

//  ,  
const int THRESHOLD_TEMP = 100;
const int WAIT = 1000000;

// B- 
const int B_THERMISTOR = 3975;                  

int analogValue = 0;
float degKelvin = 0;
float degC = 0;
float degF = 0;
float resistance = 0;

//       1
const int tempSensorPin = 1;

//      
void setup() {
    Serial.begin(9600);  
}

//    : 
//     -  SMS-  
//     -  URL-
//     -  SMS-     Twilio-
// : float tempF –     
void sendSMS( float tempF ) { 
 
    //  tempF  
    char degFstr[20];
    sprintf(degFstr, "%2f", degF);
    
    //  THRESHOLD_TEMP  
    char thresholdStr[20];
    sprintf(thresholdStr, "%d", THRESHOLD_TEMP);
    
    //  SMS-
    char smsStr[100] = "Current temperature is ";
    strcat(smsStr, degFstr);
    strcat(smsStr, " F greater than threshold temp ");
    strcat(smsStr, thresholdStr);
    strcat(smsStr, " F.");
        
    // Twilio Account = /API_VERSION/Accounts/ACCOUNT_SID
    char twilioAcc[70] = "/";
    strcat(twilioAcc, API_VERSION);
    strcat(twilioAcc, "/Accounts/");
    strcat(twilioAcc, ACCOUNT_SID);
    
    // URL path = /API_VERSION/Accounts/ACCOUNT_SID//SMS/Messages
    char postReqStr[150];
    strcpy(postReqStr, twilioAcc);
    strcat(postReqStr, "/SMS/Messages");
    Serial.println(postReqStr); 
   
    // Twilio REST
    Rest rest(ACCOUNT_SID, ACCOUNT_TOKEN);
    
    //  SMS
    vars.clear();
    vars.push_back(Var("To", "480-xxx-xxxx"));
    vars.push_back(Var("From", "480-405-xxxx"));
    vars.push_back(Var("Body", smsStr));
    string response = twilioRest.request(postReqStr, "POST", vars);
}

//       ,  
//        .
float getTemperature()
{
    analogValue = analogRead(tempSensorPin);
  
    //   ;
    resistance = (float)(1023 - analogValue) * 10000/analogValue;
 
    //       
    degKelvin = 1/(log(resistance/10000)/B_THERMISTOR + 1/298.15);
  
    //       
    degC = degKelvin - 273.15;
  
    //       
    degF = (degC * 9.0) / 5.0 + 32.0;
        
    return degF;
}

//  ,        
// .   ,    , 
//   SMS-.
void loop() { 
    degF = getTemperature();
    if(degF > THRESHOLD_TEMP)
    {
        sendSMS(degF);
        delay(WAIT);
    }
}


SMS- Twilio. Grove Starter Kit Plus – , – . , Intel Edison.


software.intel.com/en-us/iot/hardware/edison/downloads
www-ssl.intel.com/content/www/us/en/do-it-yourself/edison.html
software.intel.com/en-us/iot/hardware/edison
software.intel.com/en-us/iot/library/edison-getting-started
software.intel.com/en-us/iot/hardware/devkit
www.seeedstudio.com/wiki/images/a/a1/NCP18WF104F03RC.pdf

Source: https://habr.com/ru/post/ar384761/


All Articles