[SOLVED]Not able to store data in Ubidots from esp8266 using arduino uno

Hello all,
I am. Trying to store sensors data on ubidots using Esp8266 and arduino uno.
Arduino is able to send AT commands to esp8266 and esp8266 also were able to respond for this commands (I can see the response on serial monitor).
But the data I can not able to see on ubidots.

I am giving server name as industrial.ubidots.com, and port number 80.
And I have given default token number.

Please find the source code which I am using.

#define USE_ARDUINO_INTERRUPTS true // Set-up low-level interrupts for most acurate BPM math.
#define DEBUG true
//#define USE_ARDUINO_INTERRUPTS false
#include <PulseSensorPlayground.h> // Includes the PulseSensorPlayground Library.
#include<LiquidCrystal.h> // Includes the LCD library.
#include <SoftwareSerial.h>

//Macros
#define _baudrate  9600 
#define esp8266 FALSE 
#define _rxpin      11
#define _txpin      10
#define SSID "Lokesh"
#define PASS "lokesh@123"
#define HTTPSERVER "things.ubidots.com"
#define USER_AGENT "ESP8266"
#define VERSION "1.0"
#define Threshold 550

// Variables
int BPM =0;
int pulseCounter = 0;   
int pulseState = 0;         
int lastpulseState = 0; 
float tempc =0.0;
float Temparature_F =0.0;
//int i = 0;
int a =0;
const int PulseWire = 0; // PulseSensor WIRE connected to ANALOG PIN 0
const int LED13 = 13; // The on-board Arduino LED, close to PIN 13.
const int tempin=A1;
const int  pulsePin = A0;
 
unsigned long previousMillis=0;
unsigned long interval=60000;
unsigned long currentMillis=0;

String writeApiKey = "....";
String tokenKey = "....";
String idVariable = "...."; //HeartBeat
String idVariable2 = "..."; //Temparature
String idVariable3 = "..."; //BP



SoftwareSerial esp8266( _rxpin, _txpin ); 
SoftwareSerial gsm(10, 11);
LiquidCrystal lcd(7, 6, 5, 4, 3, 2 ); 
PulseSensorPlayground pulseSensor; // Creates an instance of the PulseSensorPlayground object called "pulseSensor"


void setup() 
{
    
    pinMode(tempin,INPUT);
    pinMode(pulsePin, INPUT);
    pulseSensor.analogInput(PulseWire); 
    pulseSensor.blinkOnPulse(LED13);  
    Serial.begin( _baudrate );
    esp8266.begin( _baudrate );
	gsm.begin(_baudrate);
    delay(2000);
    if( a==0)
    {
       Serial.println("Welcome to Patient Health Monitoring IOT System..!!");
       Serial.println("Wait for a while to check Heart rate and Temparature...!!");
       a++;
    }
	
	//gsm.println("ATD7013901099;");
    //Serial.println("Called ATD7013901099");
    sendCmd("AT");
    delay(1000);
    if(esp8266.find("OK"))
    {
      Serial.println("WiFi RECEIVED: Ok\nReady to connect to AP"); 
    }
    lcd.begin(16,2);    // set up the LCD's number of columns and rows:
    
    //Configure the PulseSensor object, by assigning our variables to it.
    pulseSensor.analogInput(PulseWire);
    pulseSensor.blinkOnPulse(LED13); //auto-matically blink Arduino's LED with heartbeat.
    pulseSensor.setThreshold(Threshold);
    
    // Double-check the "pulseSensor" object was created and "began" seeing a signal.
    if (pulseSensor.begin()) 
  {
       Serial.println("Pulse Rate Sensor started..!"); //This prints one time at Arduino power-up, or on Arduino reset.
       lcd.setCursor(0,0);
       lcd.print(" Heart Rate Monitor"); //    Print a message to the LCD.
    
    }
}

int Measure_PulseRate()
{
    while(true)
    { 
        pulseState = digitalRead(pulsePin);
        if (pulseState != lastpulseState) 
        {
            if (pulseState == HIGH) 
            {
                pulseCounter++;
                currentMillis=millis();
                               
                if ((currentMillis - previousMillis) >= interval) 
                {
                    //BPM = pulseSensor.getBeatsPerMinute();  // Calls function on our pulseSensor object that returns BPM as an "int".
                    //if (pulseSensor.sawStartOfBeat()) // Constantly test to see if "a beat happened". 
                    //{            
                       BPM=pulseCounter;
                       Serial.print("Heart Rate : ");
                       Serial.println(BPM); 
                     //}
                     //char buffer1[10];
                     //BPM = dtostrf(BPM, 4, 1, buffer1);
                     //Serial.print("dtostrf_BPM : ");
                     //Serial.println(BPM); 
                  
                  delay(2000);
                  previousMillis = millis();
                  pulseCounter=0;
                  break;
                }
            }
            else 
            {
               Serial.println("pulseState is low ");
            }
            delay(50);
        }
        lastpulseState = pulseState;
    }
}

int Measure_Temparature()
{
   tempc=analogRead(tempin);
   tempc=(tempc*0.48828125);
   Serial.print("Temparature in Celcius:");
   Serial.println(tempc);
   Temparature_F = ((tempc*1.8)+32);
   Serial.print("Temparature in Fahrenheit :");
   Serial.println(Temparature_F);
   delay(1000);
}
void loop() 
{
   
   if (gsm.available())
   {
    Serial.write(gsm.read());
   }
   
   connectWiFi();
   Measure_Temparature();
   Measure_PulseRate();
   

   lcd.setCursor(0,1);
   lcd.print("BPM: BPM"); // Print phrase "BPM: "
   //lcd.print(myBPM);
   
   sendCmd("AT+CWJAP?");   
   delay(1000);
   if(esp8266.find(SSID) )
   {
     Serial.print("Found WiFi Connection:");
	 Serial.println(SSID);
     String temp = String(tempc);
     String BPM=String(BPM);
     
     updateUDots(BPM);      
     updateUDots1(temp); 
     
     delay(5000); 
   }
   else
   {
     Serial.print("Reconnecting WiFi .....");
     sendCmd("AT");
     delay(3000);
     if(esp8266.find("OK"))
   {
       Serial.println("wifi");
       Serial.println("RECEIVED: OK\nReady to connect to AP");
       connectWiFi();
     }
   }
}

void updateUDots( String T)                  
{
  String cmd = "AT+CIPSTART=\"TCP\",\"";
  cmd += "50.23.124.66"; 
  cmd += "\",80";
  sendCmd(cmd);
  delay(10000);
  if( esp8266.find( "Error" ) ){
    Serial.print( "RECEIVED: Error\nExit1" );
    return;
  }
  String getStr = "GET /api/postvalue?token=";
  getStr += tokenKey;
  getStr +="&variable=";
  getStr +=idVariable;
  getStr +="&value=";
  getStr += String(T);
  getStr += "\r\n\r\n";
  esp8266.print( "AT+CIPSEND=" );
  esp8266.println( getStr.length() );
  if(esp8266.find( ">" ) ){
    Serial.print(">");
    Serial.print(getStr);
    esp8266.print(getStr);    
  }
  else{
    //sendCmd( "AT+CIPCLOSE" );
  }
  if (esp8266.available()) {
    Serial.write(esp8266.read());
  }
  delay(10000);
}
void updateUDots1( String T)                    
{
  String cmd = "AT+CIPSTART=\"TCP\",\"";
  cmd += "50.23.124.66"; 
  cmd += "\",80";
  sendCmd(cmd);
  delay(10000);
  if( esp8266.find( "Error" ) ){
    Serial.print( "RECEIVED: Error\nExit1" );
    return;
  }
  String getStr = "GET /api/postvalue?token=";
  getStr += tokenKey;
  getStr +="&variable=";
  getStr +=idVariable2;
  getStr +="&value=";
  getStr += String(T);
  getStr += "\r\n\r\n";
  esp8266.print( "AT+CIPSEND=" );
  esp8266.println( getStr.length() );
  if(esp8266.find( ">" ) ){
    Serial.print(">");
    Serial.print(getStr);
    esp8266.print(getStr);    
  }
  else{
    
  }
  if (esp8266.available()) {
    Serial.write(esp8266.read());
  }
  delay(10000);
}

void updateUDots2( String T)                           
{
  String cmd = "AT+CIPSTART=\"TCP\",\"";
  cmd += "50.23.124.66";
  cmd += "\",80";
  sendCmd(cmd);
  delay(10000);
  if( esp8266.find( "Error" ) ){
    Serial.print( "RECEIVED: Error\nExit1" );
    return;
  }
  String getStr = "GET /api/postvalue?token=";
  getStr += tokenKey;
  getStr +="&variable=";
  getStr +=idVariable3;
  getStr +="&value=";
  getStr += String(T);
  getStr += "\r\n\r\n";
  esp8266.print( "AT+CIPSEND=" );
  esp8266.println( getStr.length() );
  if(esp8266.find( ">" ) ){
    Serial.print(">");
    Serial.print(getStr);
    esp8266.print(getStr);    
  }
  else{
  }
  if (esp8266.available()) {
    Serial.write(esp8266.read());
  }
  delay(10000);
}

void sendCmd(String cmd){
  Serial.print("SEND: ");
  Serial.println(cmd);
  esp8266.println(cmd);
}

boolean connectWiFi()
{
  esp8266.println("AT+CWMODE=1");
  delay(3000);
  String cmd="AT+CWJAP=\"";
  cmd+=SSID;
  cmd+="\",\"";
  cmd+=PASS;
  cmd+="\"";
  sendCmd(cmd);
  delay(10000);
  if(esp8266.find("OK")){
    Serial.println("RECEIVED: WiFi connected");
    return true;
    delay(10000);
  }
  else{
    Serial.println("RECEIVED: Error(Wifi not connected 1)");
    return false;
  }
  cmd = "AT+CIPMUX=0";
  sendCmd( cmd );
  if( esp8266.find( "Error") )
  {
    Serial.print( "RECEIVED: Error (Wifi not connected 2)" );
    return false;
  }
  delay(5000);
}

Hi @KotaLokesh

I hope you’re doing well.

Based on your code seems that you are sending data to things.ubidots.com please define the HTTPSERVER as industrial.api.ubidots.com and try again.

All the best,
-Isabel

Hi Isalogi…
Thanks for your time.
Any way there was a issue with token key. And now its working fine.

Hi @KotaLokesh,

Thanks for your quick response, glad to hear everything is working. Also I recommend you to change the HTTPSERVER for industrial.api.ubidots.com

Have a nice rest of your day.
-Isabel

I have mentioned it as industrial.ubidots.com. Is it fine ?
And if HTTPSETVER is different how it will effect the functionality?

Even though with things.ubidots.com may work, for stability and response time, we always recommend to use industrial.api.ubidots.com.