6 years, 10 months ago.

PAGE WEB

Hello, I use wiznet w7500 card and I have a program to turn on and off an LED by clicking a button on a web page but it does not work

Can someone help me? Here is my program:

  1. include "mbed.h"
  2. include "EthernetInterface.h"
  3. include "mbed_rpc.h"
  4. include "HTTPServer.h"
  5. include <stdio.h>
  6. include <string.h>
  1. define HTTPD_SERVER_PORT 80
  2. define HTTPD_MAX_REQ_LENGTH 1023
  3. define HTTPD_MAX_HDR_LENGTH 255
  4. define HTTPD_MAX_FNAME_LENGTH 127
  5. define HTTPD_MAX_DNAME_LENGTH 127

Serial pc(USBTX, USBRX);

char buffer[HTTPD_MAX_REQ_LENGTH+1]; char httpHeader[HTTPD_MAX_HDR_LENGTH+1]; char fileName[HTTPD_MAX_FNAME_LENGTH+1]; char dirName[HTTPD_MAX_DNAME_LENGTH+1]; char *uristr; char *eou; char *qrystr;

RpcDigitalOut led2(LED2, "led2"); RpcDigitalOut led3(LED3, "led3"); RpcDigitalOut led4(LED4, "led4");

HTTP WEB SERVER char recv_buffer[1024] = {0,}; char echoHeader[1024] = {0,}; char * findrfid = 0;

int main (void) {

pc.printf("Init end\r\n"); WEB SERVER Star printf("Wait a second...\r\n"); IP Setting..

  1. ifdef dhcp uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0x00, 0x01, 0x02}; EthernetInterface eth; eth.init(mac_addr); Use DHCP eth.connect();
  2. else uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0x00, 0x01, 0x02}; char ip_addr[] = "21.140.0.20"; char subnet_mask[] = "255.255.254.0"; char gateway_addr[] = "21.140.1.254"; EthernetInterface eth; eth.init(mac_addr, ip_addr, subnet_mask, gateway_addr); Not Use DHCP

while(1) { Wait link up if(eth.link() == true) break; } printf("Check Ethernet Link\r\n"); printf("Link up\r\n");

  1. endif

eth.connect(); printf("Server IP Address is %s\r\n", eth.getIPAddress());

TCPSocketServer server; server.bind(HTTPD_SERVER_PORT); printf("bind complete\r\n"); server.listen(); printf("listen complete\r\n"); while (true) { printf("Wait for new connection...\r\n"); TCPSocketConnection client; server.accept(client); client.set_blocking(false, 0); Timeout after (1.5)s

printf("Connection from: %s\r\n", client.get_address());

while (true) { int n = client.receive(recv_buffer, sizeof(recv_buffer)); if (n <= 0) break; n = n < 0

print received message to terminal recv_buffer[n] = '\0'; printf("Received message from Client :'%s'\r\n",recv_buffer); if(recv_buffer[0] == 'G' && recv_buffer[1] == 'E' && recv_buffer[2] == 'T') { printf("GET request incomming.\n\r");

setup http response header + data char send_buffer[]={ "<!DOCTYPE HTML>" "\r\n\n\r<html>" "\n\r\n\r\n\r<head>" "\n\r<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\">" "\n\r<title>Wizwiki-W7500 Web Server</title>\n\r<meta name=\"generator\">" "\n\r</head>\n\r\n\r" "<body bgcolor=\"white\" text=\"black\" link=\"blue\" vlink=\"purple\" alink=\"red\">\r\n" "<h1>Wizwiki-W7500</h1>\r\n" "<p><form methode=\"GET\">\r\n" "<center>" "<input type='button' value='LED1on ' ID='btn_LED1a' onclick='led1.wrte(1)' > <br >" "<br>" "<input type='button' value='LED1oFF ' ID='btn_LED1b' onclick='led1.write(0)'><br>" "</center>" "\r\n</form>" "</p>\r\n" "</body>\n\r" "</html>\r\n" };

sprintf(echoHeader,"HTTP/1.1 200 OK\n\rContent-Length: %d\n\rContent-Type: text/html\n\rConnection: Closen\n\rRefresh: 5\n\r\n\r\n\r",strlen(send_buffer)); client.send(echoHeader,strlen(echoHeader)); client.send(send_buffer,strlen(send_buffer));

} if (n <= 0) break; } client.close(); } }

2 Answers

6 years, 10 months ago.

Si vous voulez recevoir plus de reponses il faut poser les question en anglais...

In your case it looks like you tried to implement the EthernetInterface.h library on a Wiznet board. This will not work. You need to use the Wiznet library. Search in the compiler "import" for "W7500" or Wiznet and you will find examples of how to implement the code using their library.

ok i will try

posted by eric belouet 07 Jun 2017

The EthernetInterface library I used in my program is the WiznetInterface I imported and the Wiznet library that I found it for w5500.

posted by eric belouet 07 Jun 2017
posted by Zoltan Hudak 07 Jun 2017
6 years, 10 months ago.

Hello Amy,
You might start with this demo, if you use mbed 2 or this one, in case you use mbed 5. Then delete the EthernetInterface library, import the WIZnetInterface library, compile and see how it works.

NOTE: There is a demo also for the WIZ5500 boards but it's using a differenct library.

TIP FOR EDITING: You can copy and paste your code here as text and enclose it within <<code>> and <</code>> tags as below (each marker on separate line). Then it's going to be displayed in frame as formatted code.

<<code>>
#include "mbed.h"

DigitalOut led1(LED1);

int main()
{
    while (1) {
        led1 = !led1;
        wait(0.5);
    }
}
<</code>>