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

1 visualizzazione (ultimi 30 giorni)
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 Commenti
Wade Campbell
Wade Campbell il 27 Nov 2019
Would appreciate some help on this. Any suggestions/theories???
Wade Campbell
Wade Campbell il 30 Nov 2019
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.

Accedi per commentare.

Risposta accettata

Vinod
Vinod il 1 Dic 2019
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.

Più risposte (0)

Community

Più risposte nel  ThingSpeak Community

Categorie

Scopri di più su Read Data from Channel in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by