Example sketches for the new Arduino IDE for ESP8266

Moderator: igrr

User avatar
By biobier
#15856 Nice code thanks!
Only having an issue wiht the image. I just get a blue square. Is that correct?

And one question: How to genereate the code for an image?
User avatar
By biobier
#16425
taoyanren wrote:on WIFI_AP_STA mode, I can only access the station ip webserver but can not open AP ip webserver( http://192.168.4.1/) at the same time. Why?


Similar issue here. I want to have a config page in AP mode but does not work. This can be tested with this simple code:
Code: Select all#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
 
String form = "<form action='led'><input type='radio' name='state' value='1' checked>On<input type='radio' name='state' value='0'>Off<input type='submit' value='Submit'></form>";
 
ESP8266WebServer server(80);

const int led = 13;
 
void handle_led() {
  int state = server.arg("state").toInt();
 
  digitalWrite(led, state);
  server.send(200, "text/plain", String("LED is now ") + ((state)?"on":"off"));
}

void setup(void) {
  Serial.begin(115200);
  Serial.println("");
  pinMode(led, OUTPUT);
 
  WiFi.mode(WIFI_STA);
  WiFi.disconnect();
  delay(100);
  WiFi.softAP("ESP_WiFiSwitch");
    Serial.println(WiFi.softAPIP());
   
   server.on("/", [](){
   server.send(200, "text/html", form);
  });
 
  server.on("/led", handle_led);
  server.begin();
  Serial.println("HTTP server started");
}
 
void loop(void) {
  server.handleClient();
}
User avatar
By matkar
#21668 Hi, thank you very much for the example!
It works great except for the image page. When I try to load 192.168.4.1/showled or 192.168.4.1/led.png the page responds it can't display the picture because it contains errors. I've tried to load the page with Firefox and Chrome...
I've compiled the example with a different png picture as well but to no avail.
Anybody else has the same problem?

Regards,
Mat
User avatar
By tommybee
#22854 Same to me, the Picture don't show up !!!
This part of code don't work!!

void handle_image() {
server.send(200, "image/png", ""); //nothing is transmitted, that's ok here cause of the ,"");
WiFiClient client = server.client();
client.write(image, sizeof(image)); //also nothing is transmitted, that's not ok here !!!!!!
}

I'm on Version 1.6.4-673-g8cd3697
:?: :?: :?: :?: :?: :?: