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
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;
}
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
I really don't know what to do anymore..