Hi, I’m new here. I started a project and getting the often quoted Invalid Token Issue. As said, I read all the previous Solved answers and tried everything as far as I can understand. Still mine says Invalid auth token. I hope someone can point out what I’m doing wrong. Code compiles and runs without issue. But the serial monitor is always showing invalid auth token.
My Hardware mode is ESP8266. Communication type - Sim800L (I think that’s what you are asking here).
Smartphone Version Android 10. Sony Xperia XZ3
Blynk server
Library Version Tried 1.1 and 0.6.1.
#define BLYNK_TEMPLATE_ID "TMPLrzuqxrUm"
#define BLYNK_DEVICE_NAME "Indrajith"
#define BLYNK_AUTH_TOKEN "BdXKqVOq66d9sh2ngldBB_3rcaXGFGxs"
//------------------------------------------------------------------
#define BLYNK_PRINT Serial
#define TINY_GSM_MODEM_SIM800
//------------------------------------------------------------------
#include "Adafruit_FONA.h"
#include <SoftwareSerial.h>
//GPS Module RX pin to NodeMCU D3
//GPS Module TX pin to NodeMCU D4
#define rxPin 0
#define txPin 2
#define FONA_RST 13
SoftwareSerial Sim800L(rxPin,txPin);
SoftwareSerial *fonaSerial = &Sim800L;
//Hardware serial is also possible! for ESP32
//HardwareSerial *fonaSerial = &Serial2;
Adafruit_FONA fona = Adafruit_FONA(FONA_RST);
//------------------------------------------------------------------
#include <TinyGsmClient.h>
#include <BlynkSimpleTinyGSM.h>
//------------------------------------------------------------------
char auth[] = BLYNK_AUTH_TOKEN;
char apn[] = "hutch3g";
char user[] = "";
char pass[] = "";
//------------------------------------------------------------------
TinyGsm modem(fona);
BlynkTimer timer;
//------------------------------------------------------------------
//NOTE: Enter the phone number that you want to register with the project
//You can only control the project, with the phone number you entered here
//Must enter your personal phone number with country code.
//Make Sure: never enter the gsm module's phone number here.
const String PHONE = "+94777984078";
//------------------------------------------------------------------
#define pin_relay1 14
//------------------------------------------------------------------
int state_relay1 = 0;
//------------------------------------------------------------------
//Change the virtual pins, as you have set in the blynk account.
#define virtual_pin1 V1
//------------------------------------------------------------------
String gsm_buff ="";
char sendsms[15];
char caller_id[32];
char sms_buffer[255];
int len=0;
//------------------------------------------------------------------
BLYNK_WRITE(virtual_pin1) {
state_relay1 = param.asInt();
digitalWrite(pin_relay1, state_relay1);
Serial.print("Relay 1 is ");
if(state_relay1==0)
Serial.println("OFF");
else
Serial.println("ON");
}
//------------------------------------------------------------------
void handle_sms(){
while(Serial.available()) {
fona.println(Serial.readString());
}
//MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
gsm_buff ="";
//+CMTI: "SM",1 (here! 1 is slot)
int slot = 0;
uint16_t smslen;
//MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
//any data available from the fona?
gsm_buff= fona.readString();
//if(gsm_buff.length() > 0)
//{Serial.println();Serial.println(gsm_buff);}
len = gsm_buff.length();
//MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
//if(gsm_buff.indexOf("+CMTI:")) {
if (len >10) {
gsm_buff =gsm_buff.substring(14,len);
slot = gsm_buff.toInt();
Serial.print("Slot: ");
Serial.println(slot);
if (slot == 0) {
return;
}
//------------------------------------------------------------
if (!fona.readSMS(slot, sms_buffer, 250, &smslen)) { // pass in buffer and max len!
Serial.println(F("Failed!"));
return;
}
//------------------------------------------------------------
if (! fona.getSMSSender(slot, caller_id, 31)) {
Serial.println("Didn't find SMS message in slot!");
return;
}
//------------------------------------------------------------
if(PHONE != String(caller_id)){
Serial.println("The phone number is not Registered.");
Serial.println("Please use the Registered Phone Number.");
}
else
{
//_________________________________________
String sms_temp = sms_buffer;
sms_temp.toLowerCase();
String caller_temp = caller_id;
Serial.println("SMS: "+sms_temp);
Serial.println("From: "+caller_temp);
//_________________________________________
if(sms_temp == "1on"){
state_relay1 =1;
digitalWrite(pin_relay1, HIGH);
Blynk.virtualWrite(virtual_pin1, state_relay1);
fona.sendSMS(caller_id, "Relay 1 is ON");
Serial.println("Response: Relay 1 is ON");
}
//_________________________________________
if(sms_temp == "1off"){
state_relay1 =0;
digitalWrite(pin_relay1, LOW);
Blynk.virtualWrite(virtual_pin1, state_relay1);
fona.sendSMS(caller_id, "Relay 1 is OFF");
Serial.println("Response: Relay 1 is OFF");
}
//_________________________________________
else
{
fona.sendSMS(caller_id, "ERROR: Send SMS with valid command");
}
//_________________________________________
}
//------------------------------------------------------------
fona.deleteSMS(slot);
fona.print(F("AT+CMGD=1,4\n\r"));
fona.print(F("AT+CMGDA= \"DEL ALL\""));
//------------------------------------------------------------
}
//MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
}
void setup()
{
Serial.begin(115200);
//--------------------------------------------------------------------
pinMode(pin_relay1, OUTPUT);
//--------------------------------------------------------------------
//During Starting all Relays should TURN OFF
digitalWrite(pin_relay1, LOW);
//--------------------------------------------------------------------
delay(2000);
fonaSerial->begin(9600);
if (! fona.begin(*fonaSerial)) {
Serial.println(F("Couldn't find FONA"));
while(1);
}
//--------------------------------------------------------------------
Serial.println(F("FONA is OK"));
fona.println("AT+CMGF=1"); // Configuring TEXT mode
delay(1000);
fona.print ("AT+CSMP=17,167,0,0\r");// Configuring TEXT mode
delay(1000);
fona.print("AT+CNMI=2,1\r\n"); //set up the fona to send a +CMTI notification when an SMS is received
//fona.println(F("AT+CMGDA=\"DEL ALL\""));
//delay(5000);
delay(1000);
Serial.println("FONA Ready");
//--------------------------------------------------------------------
modem.restart();
// Unlock your SIM card with a PIN
//modem.simUnlock("1234");
Blynk.begin(auth, modem, apn, user, pass);
Blynk.virtualWrite(virtual_pin1, state_relay1);
//--------------------------------------------------------------------
timer.setInterval(2L, handle_sms);
}
void loop()
{
Blynk.run();
timer.run();
}