i want read string or characters from webserver like
please provide code for this
please.............
i want read string or characters from webserver like
please provide code for this
please.............
Sorry, it doesn't work like that. If you are stuck on a specific problem with your program / sketch, post the details and someone may try to help. If you wish to engage the services of a professional programmer to write the sketch for you then you need to post in the 'Gigs and collaborations' section.
const int rp = 4;
const int p;
#include <ESP8266WiFi.h>
const char* ssid = "manju";
const char* password = "12345678";
// Create an instance of the server
// specify the port to listen on as an argument
WiFiServer server(80);
void setup() {
Serial.begin(115200);
delay(10);
// prepare GPIO2
pinMode(rp, OUTPUT);
analogWrite(rp, 0);
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
// Start the server
server.begin();
Serial.println("Server started");
// Print the IP address
Serial.println(WiFi.localIP());
}
void loop() {
// Check if a client has connected
WiFiClient client = server.available();
if (!client) {
return;
}
// Wait until the client sends some data
Serial.println("new client");
while(!client.available()){
delay(1);
}
// Read the first line of the request
String req = client.readStringUntil('\r');
Serial.println(req);
client.flush();
while(client.available()>0)
{
char a=(client.read()-48)*100;
char b=(client.read()-48)*10;
char c=(client.read()-48);
}
p=(a+b+c);
setcolor(p);
client.flush();
String s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<!DOCTYPE HTML>\r\n<html>\r\nTHE PWM VALUE is ";
s += "</html>\n";
client.print(P);
}
void setcolor(int r)
{
analogWrite(rp,r);
}
while(client.available()>0)
{
char a=(client.read()-48)*100;
char b=(client.read()-48)*10;
char c=(client.read()-48);
}
Check to see that there's at least one character to read, then go ahead and read all three of them.
Fail.
p=(a+b+c);
You also have a scope issue, but I suspect the compiler already told you that.
Please use code tags when posting code.
in the above code what i want to change if i want to give input like
http://ip_adds/3_digit_integer
ex: http://192.168.44.5/123
means how to read any integer number from web server like as mention above.
please help me.........................
Fix the obvious problems, retest and if you've still got problems, post your code (use code tags) AND your observations.
const int rp = 4;
int p;
#include <ESP8266WiFi.h>
const char* ssid = "ravi";
const char* password = "anji1234";
// Create an instance of the server
// specify the port to listen on as an argument
WiFiServer server(80);
void setup() {
Serial.begin(115200);
delay(10);
// prepare GPIO2
pinMode(rp, OUTPUT);
analogWrite(rp, 0);
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
// Start the server
server.begin();
Serial.println("Server started");
// Print the IP address
Serial.println(WiFi.localIP());
}
void loop() {
// Check if a client has connected
WiFiClient client = server.available();
if (!client) {
return;
}
// Wait until the client sends some data
Serial.println("new client");
while(!client.available()){
delay(1);
}
// Read the first line of the request
String req = client.readStringUntil('\r');
Serial.println(req);
client.flush();
char a=(client.read()-48)*100;
char b=(client.read()-48)*10;
char c=(client.read()-48);
p=(a+b+c);
setcolor(p);
client.flush();
String s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<!DOCTYPE HTML>\r\n<html>\r\nTHE PWM VALUE is ";
s += "</html>\n";
client.print(p);
}
void setcolor(int r)
{
analogWrite(rp,r);
}
in the above code i am not getting p value as enter, is there is any change required to convert as integer value
Now you're reading data without checking to see if there's any data to read.
For the third time, please use code tags when posting code.
thank you for your immidiate reply,
it is not giving any error but i am not getting required output.
i have entered throgh web server as http://192.168.55.3/123
in web page it was displayed as "THE PWM value is 449 ",
but actually it has to disply as "THE PWM value is" . where is the mistake.
client.flush();
char a=(client.read()-48)*100;
char b=(client.read()-48)*10;
char c=(client.read()-48);
Dump all the client data, regardless of whether there was any unread data. Then read three bytes that have arrived in the last 60 nanoseconds. Just how much data do you think arrived in that period of time? Can you say none? I knew you could!
Since it appears you don't know what code tags are, please read Nick Gammon's two posts at the top of this Forum about guidelines for posting here. It will make it easier for us to help you. Also, using all capital letters is like yelling at someone...don't do that here.
WiFiClient client = server.available();
if (!client) {
return;
}
// Wait until the client sends some data
Serial.println("new client");
while(!client.available()){
delay(1);
}
// Read the first line of the request
String req = client.readStringUntil('\r');
Serial.println(req);
client.flush();
char a=(client.read()-48)*100;
char b=(client.read()-48)*10;
char c=(client.read()-48);
p=(a+b+c);
in the above programe where i need to change to read n length of string.
// Read the first line of the request
String req = client.readStringUntil('\r');
Serial.println(req);
client.flush();
char a=(client.read()-48)*100;
char b=(client.read()-48)*10;
char c=(client.read()-48);
p=(a+b+c);
You aren't paying attention.
I'm done trying to help you.