Can't connect to api.asksensors.com...

Post Reply
imagination *-*
Noob
Posts: 3
Joined: Fri Sep 18, 2020 11:58 am

Can't connect to api.asksensors.com...

Post by imagination *-* » Fri Sep 18, 2020 12:07 pm

Hi,

I've been trying for hours but I just can't get connected to the server using the test codes given by asksensors for ESP8266.

Help please :cry:

This is the code:

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-2020
* github: https://github.com/asksensors/AskSensors-Arduino-WiFi
*/
#include <SoftwareSerial.h>


// serial config
#define RX 10
#define TX 11
SoftwareSerial AT(RX,TX);
// TODO: change user config
String ssid = "Galaxy s10e"; //Wifi SSID
String password = "james1234"; //Wifi Password
String apiKeyIn = "dx5JGwaidzyQjPnmANRiuGfqWnMNvXDw"; // API Key
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(9600);
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(20000); // 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;
}

This is the result,
failure.PNG
failure.PNG (19.78 KiB) Viewed 30030 times
I've tried with https://api.asksensors.com/write/
&
http://api.asksensors.com/
&
https://asksensors.com/api.asksensors/write/

Also when compiling & uploading have these warnings of which I do not know how to solve. I wonder if this is the root cause :?
errors.PNG
errors.PNG (23.56 KiB) Viewed 30025 times

I really don't know what to do anymore.. :cry:

AskGuru
Site Admin
Posts: 15
Joined: Sat Dec 15, 2018 5:14 pm

Re: Can't connect to api.asksensors.com...

Post by AskGuru » Fri Sep 18, 2020 5:06 pm

Hi,

Please try to connect to another site for verifying wifi connection. Try also to send data to your sensor directly by using browser : https://api.asksensors.com/write/apiKeyIn?module1=value1

Thanks

imagination *-*
Noob
Posts: 3
Joined: Fri Sep 18, 2020 11:58 am

Re: Can't connect to api.asksensors.com...

Post by imagination *-* » Sat Sep 19, 2020 12:53 am

Hi AskGuru,

I got this in my browser. I don't quite understand what it's supposed to do.
raw.PNG
raw.PNG (11.05 KiB) Viewed 30021 times
I tried to connect to google.com,
goole.PNG
goole.PNG (12.49 KiB) Viewed 30021 times
but it still fails,
failed.PNG
failed.PNG (17.16 KiB) Viewed 30021 times

AskGuru
Site Admin
Posts: 15
Joined: Sat Dec 15, 2018 5:14 pm

Re: Can't connect to api.asksensors.com...

Post by AskGuru » Mon Sep 21, 2020 5:26 pm

imagination *-* wrote:
Sat Sep 19, 2020 12:53 am

I got this in my browser. I don't quite understand what it's supposed to do.
That's mean that your Apikey In is correct and your sensor has successfully received the value 'value1'.

The code on the Github has been tested many times and it's worked without problem. If your wifi ids are correct so the problem can only come from hardware.

Post Reply