Problem with HTTP connection to api asksensor URL Failed

Post Reply
skulltrap
Noob
Posts: 1
Joined: Wed Aug 28, 2019 5:52 pm

Problem with HTTP connection to api asksensor URL Failed

Post by skulltrap » Wed Aug 28, 2019 6:33 pm

Hello friends,

I'm very happy with the platform, but I can not create a connection between ESP8266 to URL in the code called "api.asksensors.com", I'm using this code exactly https://github.com/asksensors/AskSensor ... T_http.ino.

So here I share my code and some pictures:

My code is this moment is:

Code: Select all

/*
  Connect Arduino WiFi to AskSensors
 * Description:  This sketch connects the Arduino to AskSensors IoT Platform (https://asksensors.com) using an ESP8266 WiFi.
 *  Author: https://asksensors.com, 2018
 *  github: https://github.com/asksensors
 */
 

#include <SoftwareSerial.h>

// serial config
#define     RX    10
#define     TX    11
SoftwareSerial AT(RX,TX); 

// TODO: change user config
String ssid     = "LOZANO"; //Wifi SSID
String password = "38250452"; //Wifi Password
String apiKeyIn = "lUGRsQpq8NxGaK1tNxvFpixmxTTDpVwc"; // API Key
const unsigned int writeInterval = 25000; // write interval (in ms)

// ASKSENSORS API host config
String host = "api.asksensors.com";  // API host name
String port = "80";      // port

int AT_cmd_time; 
boolean AT_cmd_result = false; 

void setup() {
  Serial.begin(9600);
  // open serial 
  Serial.println("*****************************************************");
  Serial.println("********** Program Start : Connect Arduino WiFi to AskSensors");
  AT.begin(115200);
  Serial.println("Initiate AT commands with ESP8266 ");
  sendATcmd("AT",5,"OK");
  sendATcmd("AT+CWMODE=1",5,"OK");
  Serial.print("Connecting to WiFi:");
  Serial.println(ssid);
  sendATcmd("AT+CWJAP=\""+ ssid +"\",\""+ password +"\"",20,"OK");
}

void loop() {

 // Create the URL for the request
  String url = "GET /write/";
  url += apiKeyIn;
  url += "?module1=";
  url += random(10, 100);
  Serial.println("*****************************************************");
  Serial.println("********** Open TCP connection ");
  sendATcmd("AT+CIPMUX=1", 10, "OK");
  sendATcmd("AT+CIPSTART=0, \"TCP\",\"" + host +"\"," + port, 20, "OK");
  sendATcmd("AT+CIPSEND=0," + String(url.length() + 4), 10, ">");
  
  Serial.print("********** requesting URL: ");
  Serial.println(url);
  AT.println(url);
  delay(2000);
  sendATcmd("AT+CIPCLOSE=0", 10, "OK");
  
  Serial.println("********** Close TCP Connection ");
  Serial.println("*****************************************************");
  
  delay(writeInterval);   // delay
  }



// sendATcmd
void sendATcmd(String AT_cmd, int AT_cmd_maxTime, char readReplay[]) {
  Serial.print("AT command:");
  Serial.println(AT_cmd);

  while(AT_cmd_time < (AT_cmd_maxTime)) {
    AT.println(AT_cmd);
    if(AT.find(readReplay)) {
      AT_cmd_result = true;
      break;
    }
  
    AT_cmd_time++;
  }
  Serial.print("...Result:");
  if(AT_cmd_result == true) {
    Serial.println("DONE");
    AT_cmd_time = 0;
  }
  
  if(AT_cmd_result == false) {
    Serial.println("FAILED");
    AT_cmd_time = 0;
  }
  
  AT_cmd_result = false;
 }
The answer from serial monitor is this:

Image

In the imagen you can see the problem in the yellow square. What can I do?

I add this information, in the space for the original URL in the code this (String host = "api.asksensors.com"; // API host name) I tried with those:

http://api.asksensors.com
https://api.asksensors.com
https://api.asksensors.com/write
http://api.asksensors.com/write
https://www.asksensors.com
http://www.asksensors.com
https://asksensors.com
http://asksensors.com

Each URL with differents variants I tried this solution in the forum viewtopic.php?f=6&t=13 but I had no results, so I need your help.

Thank you,

Regards,

Andrés L.

Guru
Simple
Posts: 20
Joined: Tue Dec 18, 2018 11:36 pm
Contact:

Re: Problem with HTTP connection to api asksensor URL Failed

Post by Guru » Thu Aug 29, 2019 12:05 pm

Hello,

Thank you for trying AskSensors.
It seems that your device is not able to connect to the AskSensors server.
First, We should confirm that your device is able to connect to internet: Please replace the host server "api.asksensors.com" by "www.google.com".
Are you able to connect ?

Post Reply