I am using an ESP8266 and an Arduino Uno R3. I am trying to be able to set up so I can post to a website. First I want to be able to do a get request but I am not getting any thing back. I am trying to do a get request to the website https://reqres.in/api/uses/2 (and I have surrounded the get request in the code with //) this isnt the full code just the relevant code because the whole thing is rather big. I know almost nothing about HTTP so anything would be helpful. Also, if you know how to post to the website using AT command I would appreciate help with that as well.
Heres a thing I used to help me but obviously i am here still asking for more help arduino uno - Get data from website with ESP8266 using AT commands - Arduino Stack Exchange
#include <SoftwareSerial.h>
#include <Wire.h>
#include <WiFi.h>
////sensor////
//i
/////////////
int serialRx = 2; // software serial RX TX
int serialTx = 3;
int f= 0;
int i =1;
int j = 0;
String inMsg ; //idk
String IP; //IP Address
SoftwareSerial portOne(serialRx, serialTx); // sets up the ports 3 and 2 as the serial ports
void setup() {
/****************************************************************************************/
Serial.begin(115200);
while (!Serial) {
; // wait for serial port to connect.
}
portOne.begin(115200); // Start software serial port to communicate with the ESP8266 because it defaults to the BAUD rate of 115200 but this is not stable
delay(100);
sendToWifi("AT+UART_DEF=9600,8,1,0,0",100); //this changes the BAUD rate of the ESP8266 to 9600
delay(200); //this gives it a second to connect
Serial.flush(); //flush all the previous serial data
Serial.begin(9600); //changes the serial connection BAUD rate
while (!Serial) {
; // wait for serial port to connect.
}
/////////////////////
portOne.begin(9600); // Start software serial port
delay(100);
sendToWifi("AT+RST",100);
delay(1000);
//sendToWifi("ATE1",100); // set Echo Off. Otherwise echo was ON.(no idea what this is for)
sendToWifi("AT+CWMODE=3",100); // 1) 2) 3)set as both an access point and a server
IP=sendToWifi("AT+CIFSR",500); // get ip address of the WIFI chip and save it to a variable for use later
sendToWifi("AT+CIPMUX=0",500); // configure for multiple connections
sendToWifi("AT+CIPSERVER=1,80",2000); // turn on server on port 80
sendToWifi("AT+CWJAP=\"SSID\",\"Password\"",2000);
delay(3000);
sendToWifi("AT+CWJAP?",500); ////this sees if it is connected to a router
delay(500);
sendToWifi("AT+CIFSR",500); // Check the module's ip and test connection
delay(2000);
sendToWifi("AT+CIPSTART=\"TCP\",\"reqres.in\",80",2000);// starts connection with webserver
delay(100);
sendToWifi("AT+CIPSEND=80",800); // set byte length to something and this will be the length of the data the server is prepared to accept
sendToWifi("GET reqres. HTTP/1.1",3000);
printResponse;
}
void loop() {
}
void printResponse() {
while (portOne.available()) {
Serial.println(portOne.readStringUntil('\n'));
}
}
String sendToWifi(String command, const int timeout){
String response = "";
Serial.print("Sent command to ESP8266-E12: ");
Serial.println(command);
delay(50);
portOne.println(command);
long int time = millis();
while( (time+timeout) > millis())
{
while(portOne.available())
{
char c = portOne.read(); //read string character by character
response= response + c;
}
}
Serial.print("Response from ESP8266: ");
Serial.println(response);
return (response);
}
String readfromWifi(){
char arrayInMsg[100];
String tempStr; ///// changed from string to CHAR
int count =0;
while( portOne.available() > 0 ){ //portOne needs to be opened
delay(1);
arrayInMsg[count]= portOne.read();
delay(20);
// getout if you see CR or LF
if (arrayInMsg[count] == "\n" or arrayInMsg[count] == "\r") break;
count++;
}
arrayInMsg[count] = '\0'; // Null terminate finally
tempStr = String(arrayInMsg); // cast it to string ///// changed from string to CHAR
tempStr.trim(); // precaution
Serial.print("Msg Received = ");
Serial.println(tempStr);
return tempStr;
}
/***********************************************************************/