0

I'm doing a project on STM32F767ZI. Error I became when I compiled my code was "EthernetInterface library is not supported on your target". I researched on google and found someones F7_Ethernet library, but the program still can't be compiled because of errors inside the library.

The code is shown below:

//Example - Voice Controlled Door Access 
#include "mbed.h" 
//#include "EthernetInterface.h" 
//#include "F7_Ethernet.h"
#include <stdio.h> 
#include <string> 
#include "rtos.h" 
#include "Servo.h"

#if defined(TARGET_NUCLEO_F767ZI)    
Servo myservo(D9);
#endif
#define PORT   80

void web_server(void const *args) {    
TCPSocketServer server;    
TCPSocketConnection client;         
server.bind(PORT);    
server.listen();
    while(true){        
    printf("Waiting for connection...\r\n");        
    int32_t status = server.accept(client);        
    printf("Connection from: %s\r\n", client.get_address());           
         if (status>=0)    
        {          
             char buffer[1024] = {};          
             int n= client.receive(buffer, 1023);          
             printf("Received Data:  %d\n\r\n\r%.*s\n\r",strlen(buffer),strlen(buffer),buffer);             
           //GET /q=open+sesame HTTP/1.1          
             char item[13];             
             for(int k=0; k<13; k++){         
                  item[k]= buffer[k+5];          
                  }
char Body[1024] = {};            
    if (strcmp(item,"q=open+sesame")==0){       
        sprintf(Body,"<html><title></title><body><h1>Door  Open</h1></body></html>\n\r\n\r");           
        //move the servo to open the door,              
        myservo = 1;             
        // wait for 5 seconds, close the door              
        wait(5);              
        //close the door              
        myservo = 0;        
         }          
    else{           
        sprintf(Body,"<html><title></title><body><h1>Door Not  Open</h1></body></html>\n\r\n\r");
            //do nothing with the door         
             }               
char Header[256] = {};      
sprintf(Header,"HTTP/1.1 200 OK\n\rContent-Length: %d\n\rContent- Type: text/html\n\rConnection: Keep-Alive\n\r\n\r",strlen(Body));          
client.send(Header,strlen(Header));          
client.send(Body,strlen(Body));
client.close();       
 }   
  } 
  } 
  int main() {   
   EthernetInterface eth;    
   eth.init();     
   eth.connect();    
   printf("\r\nServer IP Address is %s\r\n", eth.getIPAddress());     
     //close the door    
   myservo = 0;    
   //wait for instructions    
   web_server("");    
   while(1){}   
    }
enzo
  • 3
  • 1
  • What is your Mbed OS version? I have some TCPSocket projects for another device. I changed the target to NUCLEO_F767ZI and was able to compile without errors. I'm on mbed-os-5.14.1. – Kentaro Okuda Dec 02 '19 at 12:40
  • I updated all libraries (including mbed os) to the latest version but still can't compile my program. Can you send me your project just to try if I'm able to compile that? @KentaroOkuda – enzo Dec 02 '19 at 18:23
  • Please see my answer. I can compile the example program for NUCLEO_F767ZI. – Kentaro Okuda Dec 02 '19 at 19:54
  • @KentaroOkuda I need to thank you a lot. I tried the example you sent me and it worked. But I'm still trying to correct my example. I don't know what to use instead of TCPSocketServer and TCPSocketConnection classes that are defined in the EthernetInterface library I thought I could use. – enzo Dec 03 '19 at 09:42
  • We don't use ```TCPSocketServer``` and ```TCPSocketConnection``` in OS5 any more. We directly use ```TCPSocket```. It can ```bind```, ```accept``` and ```listen``` too. I recommend you study the latest API and go from there. If you still have difficulty, you can post a new question. – Kentaro Okuda Dec 03 '19 at 12:07
  • Okay. I'm gonna do it. Thank you so much for your help and advices. :) @KentaroOkuda – enzo Dec 03 '19 at 12:34

1 Answers1

0

I assume you are using recent Mbed OS versions (5.11~). I suggest using NetworkInterface (doc) and TCPSocket.

Once you have initialized a network interface, use TCPSocket to open a connection connect(), send data send() and receive data recv(). It can bind(), accept() and listen() too.

You can find an example program here: https://os.mbed.com/docs/mbed-os/v5.14/apis/tcpsocket.html#server-socket

Kentaro Okuda
  • 1,557
  • 2
  • 12
  • 16