ThingHTTP call to Twilio results in "AccountSid or AuthToken was incorrect"

조회 수: 2 (최근 30일)
I am using the example (to send an SMS from an Arduino) at https://www.instructables.com/id/Send-SMS-from-Arduino-over-the-Internet-using-ENC2/
I have triple checked the Twilio credentials entered into the ThingHTTP project and the ThingHTTP project's API key.
The Arduino code and the serial output text are below...
/*
Send SMS from Arduino over the Internet using ENC28J60 and Thingspeak
Change one line to use with ethernet shield
Add sensor readings in the loop and a time interval
Using Arduino UIP library from https://github.com/ntruchsess/arduino_uip
Code based on Sparkfun's data logging service data.sparkfun.com
URL encode function from http://hardwarefun.com/tutorials/url-encoding-in-arduino
*/
#include <SPI.h>
//change the following line to #include <Ethernet.h> to use the eithent shield
#include <Ethernet.h>
// Enter a MAC address for your controller below.
byte mac[] = { 0x00, 0x24, 0xd6, 0x7f, 0xa2, 0x54 };
//thingspeak server
char server[] = "api.thingspeak.com";
//if DHCP fails, use a static IP
IPAddress ip(192,168,0,199);
// Initialize the Ethernet client library
EthernetClient client;
//API key for the Thingspeak ThingHTTP already configured
const String apiKey = "<<my API code fromn ThingHTTP project>>";
//the number the message should be sent to
const String sendNumber = "<<my cell phone number>>"; // format "+1nnnnnnnnnn"
void setup()
{
Serial.begin(9600);
//set up Ethernet:
setupEthernet();
//send the sms
Serial.println("Sending SMS");
//this function will send the sms
//the first argument is the number to send to, formatted like this +12345678901
//the second argument is the body of the text message, which must be within URLEncode()
sendSMS(sendNumber, URLEncode("Hello World!"));
}
void loop()
{
}
void sendSMS(String number,String message)
{
// Make a TCP connection to remote host
Serial.print(F("server: "));
Serial.println(server);
// Serial.print("client.connect(server,80): ");
// Serial.println(client.connect(server, 80));
if (client.connect(server, 80))
{
//should look like this...
//api.thingspeak.com/apps/thinghttp/send_request?api_key={api key}&number={send to number}&message={text body}
Serial.println("client.connect(server, 80) is true");
client.print("GET /apps/thinghttp/send_request?api_key=");
client.print(apiKey);
client.print("&number=");
client.print(number);
client.print("&message=");
client.print(message);
client.println(" HTTP/1.1");
client.print("Host: ");
client.println(server);
client.println("Connection: close");
client.println();
Serial.print("GET /apps/thinghttp/send_request?api_key=");
Serial.print(apiKey);
Serial.print("&number=");
Serial.print(number);
Serial.print("&message=");
Serial.print(message);
Serial.println(" HTTP/1.1");
Serial.print("Host: ");
Serial.println(server);
Serial.println("Connection: close");
Serial.println();
Serial.println(F("TS Connection succeeded"));
}
else
{
Serial.println(F("TS Connection failed"));
}
// Check for a response from the server, and route it
// out the serial port.
if (client.connected()) {
Serial.println(F("Server response..."));
}
while (client.connected())
{
if ( client.available() )
{
char c = client.read();
Serial.print(c);
}
}
Serial.println();
Serial.println("End of reading from server");
client.stop();
}
void setupEthernet()
{
Serial.println("Setting up Ethernet...");
// start the Ethernet connection:
if (Ethernet.begin(mac) == 0) {
Serial.println(F("Failed to configure Ethernet using DHCP"));
// no point in carrying on, so do nothing forevermore:
// try to congifure using IP address instead of DHCP:
Ethernet.begin(mac, ip);
}
Serial.print("My IP address: ");
Serial.println(Ethernet.localIP());
// give the Ethernet shield a second to initialize:
delay(1000);
}
String URLEncode(const char* msg)
{
const char *hex = "0123456789abcdef";
String encodedMsg = "";
while (*msg!='\0'){
if( ('a' <= *msg && *msg <= 'z')
|| ('A' <= *msg && *msg <= 'Z')
|| ('0' <= *msg && *msg <= '9') ) {
encodedMsg += *msg;
}
else {
encodedMsg += '%';
encodedMsg += hex[*msg >> 4];
encodedMsg += hex[*msg & 15];
}
msg++;
}
return encodedMsg;
}
  댓글 수: 2
Wade Campbell
Wade Campbell 2019년 11월 27일
Would appreciate some help on this. Any suggestions/theories???
Wade Campbell
Wade Campbell 2019년 11월 30일
Got it. Pilot error... Twilio account id and auth code had a space at the end that should not have been there. Didn't realize double clicking a number selected the number with a space at the end.

댓글을 달려면 로그인하십시오.

채택된 답변

Vinod
Vinod 2019년 12월 1일
Thanks for sharing your code and the solution in your comment.
Looks like you were able to figure out the solution before we could get to your query.

추가 답변 (0개)

커뮤니티

더 많은 답변 보기:  ThingSpeak 커뮤니티

카테고리

Help CenterFile Exchange에서 Read Data from Channel에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by