Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By miranthajayathilaka
#55940 I'm trying esp8266 post request to try and send two variable values through URL. The post request i have is shown below.

client.print(String("POST ") + url +
" HTTP/1.1\r\n" + "Host: " +
host + "\r\n" + "User-Agent: Arduino/1.0\r\n" + "Cache-Control: no-cache\r\n" +
"Content-Type: application/x-www-form-urlencoded" + "\r\n" + "Connection: close\r\n\r\n" +
"Content-Length: " + post.length() + "\r\n" + post );
The post data is like this.

String post = "number=1&status=OFF";
I'm using XAMPP to host the webpage. Everything seems to work fine but after execution what i receive is this on the php page.

Notice: Undefined index: number in C:\xampp\htdocs\pumpupdate.php on line 3

Notice: Undefined index: status in C:\xampp\htdocs\pumpupdate.php on line 4
which means the the $_GET commands in the php script don't reveive the variables sent to the page's URL. When i tried manually updating the url it worked fine, which i concluded as the php file working properly.

Please advice. really appreciate the help. Thanks.
User avatar
By Ian Phill
#56762 Hello, I have been trying to connect two ESP Module for send a character "c" from Module A to Module B but I don't do nothing yet. I tried with OGMrStinky and Stoney code and nothing, the answer is connection failed...
In my project I just want to send one digit from Module A to Module B, if this is possible without TCP/IP or other thing complicated is better for me.

Thank you in advance.
I appreciate so much your help

//=================
server
//=================

#include <WiFiClient.h>

#include <ESP8266mDNS.h>
//================================================
#include <ESP8266WiFi.h>

const char *ssid = "abc";

MDNSResponder mdns; //stoney
WiFiServer server(80);

void setup() {
WiFi.disconnect(); //stoney
delay(1000);
Serial.begin(115200);
Serial.println();
Serial.print("Configuring access point...");

WiFi.mode(WIFI_STA); //stoney
WiFi.softAP(ssid);

while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); }

Serial.println("done");
IPAddress myIP = WiFi.softAPIP();
Serial.print("AP IP address: ");
Serial.println(myIP);

server.begin();
Serial.println("HTTP server started");
}

void loop() {
mdns.update(); // Check for any mDNS queries and send responses

WiFiClient client = server.available(); // Check if a client has connected
if (!client) {
//return (NOCLIENT);
Serial.println("NOCLIENT");
}

Serial.println("");
Serial.println("New client");

// Wait for data from client to become available
while (client.connected() && !client.available()) {
delay(1);
}

// Read the first line of HTTP request
String req = client.readStringUntil('\r');
}

//==================
client
//==================
#include <WiFiClient.h>

#include <ESP8266mDNS.h>

//================================
#include <ESP8266WiFi.h>

const char* ssid = "abc";

MDNSResponder mdns; //stoney
WiFiServer server(80); //stoney

IPAddress host(192,168,4,1);

void setup() {
WiFi.disconnect(); //stoney
Serial.begin(115200);
delay(100);

Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);

WiFi.mode(WIFI_STA); //stoney
WiFi.begin(ssid);

while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}

Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}

int position = 0;

void loop() {
WiFiClient client;
const char* host = "192.168.4.1";
const int httpPort = 80;

if (!client.connect(host, httpPort)) {
Serial.println("connection failed");
return;
}

String url = "/";
url += "?pos=";
url += String(position);

Serial.print("Requesting URL: ");
Serial.println(url);

// This will send the request to the server
client.print(String("GET ") + url + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Connection: close\r\n\r\n");
delay(10);

while (client.available()) {
String line = client.readStringUntil('\r');
// String line = client.readStringUntil("</html>");
Serial.println(line);

int addr_start = line.indexOf("value=\"");
int addr_end = line.indexOf('\"', addr_start + 7);

if (addr_start == -1 || addr_end == -1) {
Serial.print("no data in line");
}
else {
String req = line.substring(addr_start + 7, addr_end);
Serial.print("start: ");
Serial.println(addr_start);
Serial.print("end: ");
Serial.println(addr_end);

Serial.print("Possy: ");
Serial.println(req);
}

}
Serial.println();
Serial.println("closing connection");
}
User avatar
By mrburnette
#56775
Ian Phill wrote:Hello, I have been trying to connect two ESP Module for send a character "c" from Module A to Module B but I don't do nothing yet.<...>
In my project I just want to send one digit from Module A to Module B, if this is possible without TCP/IP or other thing complicated is better for me.
<...>


You are welcome to look over theTardis project: one ESP8266 sends ASCII and the other ESP8266(s) receive the transmission - one way because the sender uses UDP broadcasts.

Ray
User avatar
By Toto Nano
#56933 help me, What changed if you want to make esp-01 as client?
I have learned and no found reference.

Code: Select all#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <Servo.h>

const char *ssid = "mywifi"; 
const char *pw = "qwerty123";
IPAddress ip(192, 168, 0, 1);
IPAddress netmask(255, 255, 255, 0);
const int port = 9876;

const int chCount = 4;
Servo servoCh[chCount];
int chPin[] = {0, 2, 14, 12};
int chVal[] = {1500, 1500, 1500, 1500};

int usMin = 700;
int usMax = 2300;


WiFiServer server(port);
WiFiClient client;


char cmd[100];
int cmdIndex;
unsigned long lastCmdTime = 60000;
unsigned long aliveSentTime = 0;


boolean cmdStartsWith(const char *st) {
  for(int i=0; ; i++) {
    if(st[i]==0) return true;
    if(cmd[i]==0) return false;
    if(cmd[i]!=st[i]) return false;;
  }
  return false;
}


void exeCmd() {

  lastCmdTime = millis();
 
  if( cmdStartsWith("ch") ) {
    int ch = cmd[2] - '0';
    if(ch>=0 && ch<=9 && cmd[3]==' ') {
      chVal[ch] = (int)atof(cmd+4);
      if(!servoCh[ch].attached()) {
        servoCh[ch].attach(chPin[ch], usMin, usMax);
      }   
      servoCh[ch].writeMicroseconds(chVal[ch]);
    }
  }
 
  if( cmdStartsWith("ci") ) {
    int ch = cmd[2] - '0';
    if(ch>=0 && ch<=9 && cmd[3]==' ') {
      chVal[ch] = -(int)atof(cmd+4);
      if(!servoCh[ch].attached()) {
        servoCh[ch].attach(chPin[ch], usMin, usMax);
      }   
      servoCh[ch].writeMicroseconds(chVal[ch]);
    }
  }
 
  if( cmdStartsWith("ca") ) {
    int ch = cmd[2] - '0';
    if(ch>=0 && ch<=9 && cmd[3]==' ') {
      chVal[ch] = (usMax+usMin)/2 + (int)( atof(cmd+4)*51 );
      if(!servoCh[ch].attached()) {
        servoCh[ch].attach(chPin[ch], usMin, usMax);
      }   
      servoCh[ch].writeMicroseconds(chVal[ch]);
    }
  }
 
  if( cmdStartsWith("cb") ) {
    int ch = cmd[2] - '0';
    if(ch>=0 && ch<=9 && cmd[3]==' ') {
      chVal[ch] = (usMax+usMin)/2 - (int)( atof(cmd+4)*51 );
      if(!servoCh[ch].attached()) {
        servoCh[ch].attach(chPin[ch], usMin, usMax);
      }   
      servoCh[ch].writeMicroseconds(chVal[ch]);
    }
  } 
}

void setup() {

  delay(1000);

  /*for(int i=0; i<chCount; i++) {
    servoCh[i].attach(chPin[i], usMin, usMax);
    chVal[i] = (usMin + usMax)/2;
    servoCh[i].writeMicroseconds( chVal[i] );
  }*/
 
  cmdIndex = 0;
  Serial.begin(115200);

  WiFi.softAPConfig(ip, ip, netmask);
  WiFi.softAP(ssid, pw);

  server.begin();

  Serial.println("ESP8266 RC receiver 1.1 powered by RoboRemo");
  Serial.println((String)"SSID: " + ssid + "  PASS: " + pw);
  Serial.println((String)"RoboRemo app must connect to " + ip.toString() + ":" + port);
 
}

void loop() {
  if(millis() - lastCmdTime > 500) { 
    for(int i=0; i<chCount; i++) {
      servoCh[i].writeMicroseconds( (usMin + usMax)/2 );
      servoCh[i].detach();
    }
  }

  if(!client.connected()) {
    client = server.available();
    return;
  }

  if(client.available()) {
    char c = (char)client.read();

    if(c=='\n') {       
      cmd[cmdIndex] = 0;
      exeCmd(); 
      cmdIndex = 0;
    } else {     
      cmd[cmdIndex] = c;
      if(cmdIndex<99) cmdIndex++;
    }
  }

  if(millis() - aliveSentTime > 500) {
    client.write("alive 1\n");
    aliveSentTime = millis();
  }

}