32u4 Leonardo board reprogrammed?

Hello here is a different type of programming question. Can the Arduino Leonardo that has the USB host on it can it be reprogrammed to be a USB Ethernet? What i mean is that If i plug it into my computer can it be displayed as a Ethernet in my Ethernet network panel? Is this possible? The reason why I'm asking if because I would like to run a Webserver on my Pc without having to put a Ethernet shield on the Leonardo.

josephchrzempiec:
I would like to run a Webserver on my Pc without having to put a Ethernet shield on the Leonardo.

???

I was just curious if that was possible that's all.

What purpose does the leonardo serve in a web server? You could run a web server with no ethernet ports, it just wouldn't be accessible outside your own computer.

Hello David to be a local webserver that only that computer can access without having to access everything else. I know i can do that with a esp8266. But i only wanted it to be local to a computer only.

I did look up a few things and what i would have to do is Basically change the Leonardo into a RNDIS usb virtual network adapter. But in order for that to work it would no longer be able to use Arduino or arduino boot loader a lot would have to change. So Basically I would just have to use a Ethernet shield or something like a Wifi shield and or Esp8266. So for now I think I'm going to be using a esp8266.

what is your goal? you want to create a simple graphical user interface that can be used only from the computer over USB? you could use SerialUI library and the https://devicedruid.com/ extension for it to create GUI

To be honest the goal ran away from me. A while back i had a project for a Raspberry pi called RNDIS which can turn native USB into a USB Ethernet adapter without having the have a Ethernet shield or a Ethernet cable. But the most the looked into doing a project like this one the end Result is Arduino with Arduino boot loader can not do this.

However what i did find out the Arduino Atmega32u2 chip and the Atmega32u4 chip known as the Arduino Leonardo the 32u4 chip that has native USB can do RNDIS but not with a arduino boot loader on it. with that said it would need a different type of C programming boot loader.

The point of this or the goal of this project was to Run a webserver through the Native USB to Ethernet adapter to a local PC. what are the advantage and disadvantage of something like this is. Well the advantage is no Ethernet shield and no Ethernet cable a big saving cost. The disadvantage of this is well i don't see it as a disadvantage really. But it be on when the computer is powered on and online. How it gets it connected as a Ethernet is that it created a USB Ethernet host that goes into the network settings of a Computer and when that happens you can bridge that connect to your local computer network adapter to get a IP address. I have done mange network Bridges before.

What got me started on this project. I did one with using a Raspberry pi it can do a RNDIS network uSB adapter. But only the Raspbery pi zero can do this not any one else. So my goal was to figure out a way to do this with a arduino and well this is the result from it.

then you could play with Arduino Playground - SerialIP Library

Hello juraj thank you. Im looking at it and looks promising. When i get back home ill have To look at it more closely. Only thing i don't see if ip address does it automatically sign a IP address or do you have to manually add one?

josephchrzempiec:
Hello juraj thank you. Im looking at it and looks promising. When i get back home ill have To look at it more closely. Only thing i don't see if ip address does it automatically sign a IP address or do you have to manually add one?

I didn't try it, but it will be similar to direct Ethernet cable connection so no DHCP, only fixed addresses

So my next question is will it work on which board? It doesnt say. Does it need native usb or something with a ftdi/ch340 on it?

josephchrzempiec:
So my next question is will it work on which board? It doesnt say. Does it need native usb or something with a ftdi/ch340 on it?

nothing special. everything like for Serial Monitor

Hello i downloaded it and put it into my Libraries folder and tried to compile the example sketch of the helloworld. I get a error stating SerialIP.h not there. But in the folder it is there.

WARNING: Category 'Language' in library ArduinoStreaming is not valid. Setting to 'Uncategorized'
C:\Users\MYPC\Documents\Arduino\libraries\SerialIP-1.0\SerialIP\examples\HelloWorldServer\HelloWorldServer.pde:44:22: fatal error: SerialIP.h: No such file or directory

 #include <SerialIP.h>

                      ^

compilation terminated.

exit status 1
Error compiling for board Arduino/Genuino Uno.

Here is the example sketch that came from that site.

/*
 * SerialIP Hello World example.
 *
 * SerialIP is a TCP/IP stack that can be used over a serial port (a bit
 * like a dial-up Internet connection, but without the modem.)  It works with
 * stock Arduinos (no shields required.)  When attached to a PC supporting
 * SLIP, the Arduino can host network servers and access the Internet (if the
 * PC is configured to share its Internet connection of course!)
 *
 * SerialIP uses the fine uIP stack by Adam Dunkels <adam@sics.se>
 *
 * For more information see the SerialIP page on the Arduino wiki:
 *   <http://www.arduino.cc/playground/Code/SerialIP>
 *
 *      -----------------
 *
 * This Hello World example sets up a server at 192.168.5.2 on port 1000.
 * Telnet here to access the service.  The uIP stack will also respond to
 * pings to test if you have successfully established a SLIP connection to
 * the Arduino.
 *
 * SLIP connection set up under Linux:
 *
 *  # modprobe slip
 *  # slattach -L -s 115200 -p slip /dev/ttyUSB0     (see note below)
 *  # ifconfig sl0 192.168.5.1 dstaddr 192.168.5.2
 *
 *  # ping 192.168.5.2
 *  # telnet 192.168.5.2 1000
 *
 * Here 192.168.5.1 is the address you will give to your PC, and it must be
 * unique on your LAN.  192.168.5.2 is the IP you will give the Arduino.  It
 * must also be unique, and must match the address the Arduino is expecting
 * as set by the "myIP" variable below.
 *
 * Note that slattach won't return so you'll need to run ifconfig from
 * another terminal.  You can press Ctrl+C to kill slattach and release the
 * serial port, e.g. to upload another sketch.
 *
 * This example was based upon uIP hello-world by Adam Dunkels <adam@sics.se>
 * Ported to the Arduino IDE by Adam Nielsen <malvineous@shikadi.net>
 */

#include <SerialIP.h>

// The connection_data struct needs to be defined in an external file.
#include "HelloWorldData.h"

void setup() {

  // Set up the speed of our serial link.
  Serial.begin(115200);

  // Tell SerialIP which serial port to use (some boards have more than one.)
  // Currently this is limited to HardwareSerial ports, until both it and 
  // SoftwareSerial inherit from a common base class.
  SerialIP.use_device(Serial);

  // We're going to be handling uIP events ourselves.  Perhaps one day a simpler
  // interface will be implemented for the Arduino IDE, but until then...  
  SerialIP.set_uip_callback(uip_callback);

  // Set the IP address we'll be using.  Make sure this doesn't conflict with
  // any IP addresses or subnets on your LAN or you won't be able to connect to
  // either the Arduino or your LAN...
  IP_ADDR myIP = {192,168,5,2};
  IP_ADDR subnet = {255,255,255,0};
  SerialIP.begin(myIP, subnet);

  // If you'll be making outgoing connections from the Arduino to the rest of
  // the world, you'll need a gateway set up.
  //IP_ADDR gwIP = {192,168,5,1};
  //SerialIP.set_gateway(gwIP);

  // Listen for incoming connections on TCP port 1000.  Each incoming
  // connection will result in the uip_callback() function being called.
  SerialIP.listen(1000);
}

void loop() {
  // Check the serial port and process any incoming data.
  SerialIP.tick();

  // We can do other things in the loop, but be aware that the loop will
  // briefly pause while IP data is being processed.
}

void uip_callback(uip_tcp_appstate_t *s)
{
  if (uip_connected()) {

    // We want to store some data in our connections, so allocate some space
    // for it.  The connection_data struct is defined in a separate .h file,
    // due to the way the Arduino IDE works.  (typedefs come after function
    // definitions.)
    connection_data *d = (connection_data *)malloc(sizeof(connection_data));

    // Save it as SerialIP user data so we can get to it later.
    s->user = d;

    // The protosocket's read functions need a per-connection buffer to store
    // data they read.  We've got some space for this in our connection_data
    // structure, so we'll tell uIP to use that.
    PSOCK_INIT(&s->p, d->input_buffer, sizeof(d->input_buffer));

  }

  // Call/resume our protosocket handler.
  handle_connection(s, (connection_data *)s->user);

  // If the connection has been closed, release the data we allocated earlier.
  if (uip_closed()) {
    if (s->user) free(s->user);
    s->user = NULL;
  }
}

// This function is going to use uIP's protosockets to handle the connection.
// This means it must return int, because of the way the protosockets work.
// In a nutshell, when a PSOCK_* macro needs to wait for something, it will
// return from handle_connection so that other work can take place.  When the
// event is triggered, uip_callback() will call this function again and the
// switch() statement (see below) will take care of resuming execution where
// it left off.  It *looks* like this function runs from start to finish, but
// that's just an illusion to make it easier to code :-)
int handle_connection(uip_tcp_appstate_t *s, connection_data *d)
{
  // All protosockets must start with this macro.  Its internal implementation
  // is that of a switch() statement, so all code between PSOCK_BEGIN and
  // PSOCK_END is actually inside a switch block.  (This means for example,
  // that you can't declare variables in the middle of it!)
  PSOCK_BEGIN(&s->p);

  // Send some text over the connection.
  PSOCK_SEND_STR(&s->p, "Hello. What is your name?\n");

  // Read some returned text into the input buffer we set in PSOCK_INIT.  Data
  // is read until a newline (\n) is received, or the input buffer gets filled
  // up.  (Which, at 16 chars by default, isn't hard!)
  PSOCK_READTO(&s->p, '\n');

  // Since any subsequent PSOCK_* functions would overwrite the buffer, we
  // need to make a copy of it first.  We can't use a local variable for this,
  // because any PSOCK_* macro may make the function return and resume later,
  // thus losing the data in any local variables.  This is why uip_callback
  // has allocated the connection_data structure for us to use instead.  (You
  // can add/remove other variables in this struct to store different data.
  // See the other file in this sketch, serialip_conn.h)
  strncpy(d->name, d->input_buffer, sizeof(d->name));
  // Note that this will misbehave when the input buffer overflows (i.e.
  // more than 16 characters are typed in) but hey, this is supposed to be
  // a simple example.  Fixing this problem will be left as an exercise for
  // the reader :-)

  // Send some more data over the connection.
  PSOCK_SEND_STR(&s->p, "Hello ");
  PSOCK_SEND_STR(&s->p, d->name);

  // Disconnect.
  PSOCK_CLOSE(&s->p);

  // All protosockets must end with this macro.  It closes the switch().
  PSOCK_END(&s->p);
}

You directory structure is Arduino>libraries>SerialIP-1.0>SerialIP

Move SerialIP up into the libraries folder, it isn't being found in the SerialIP-1.0 folder.

You will find that there are a few corrections that need to be made before it will run, several places where WProgram.h has to be changed to Arduino.h. I was looking at that library a couple of weeks ago, think I finally resorted to loading an ancient version of the IDE just to get it to compile.

I'm so out of it and didn't notice that. So i did make the change and that part did work. But got a new error stating WProgram.h not available. I looked it up and it said to change from WProgram.h to Arduino.h in the .h and .cpp file So i did that and closed everything out after that i reopen the sketch tried it again and now error is #include <Ardino.h> Not available.

I used notepad Plus Plus editor.

Edit my last statement i missed one spot where it was suppose to be changed. And i did that. I finally have a good compile and upload.

But after final upload nothing happens. Nothing from Serial monitor nothing change on the PC there are links on the site but all links say page 404 can not be found.

=Not sure what to do next?

I never did get it working myself, not sure whether the problem was in the computer or the arduino, and I was playing with it mainly out of curiosity and didn't want to spend the time on it. SerialIP is a very old library and doesn't seem to have been maintained.

In linux there are things that can be done. But no detail in windows on what to do after uploading the sketch and library.