Using ENC28J60 to communicate over the internet

enc28j60

I've read that we can interface a microcontroller to the ethernet using ENC28J60 ethernet interface chip, but can I use the same to interface the controller with the internet? I've googled about it for over a month and i felt that there is no single proper explanation which covers all parts of this concept.

I got to know how to interface the ENC28J60 with the controller through SPI, and how to configure ENC28J60 IC, but then I ran into something called as a "TCP/IP" stack. Now this is supposed to be a set of internet protocols. But all I want to do is a simple webserver so isn't UDP/IP and ARP enough to do this?? why will I need TCP?

Best Answer

You can use the ENC28J60 over the Internet but to access your device from a web browser you will need TCP/IP support, from the Hypertext Transfer Protocol article on Wikipedia:

HTTP is an application layer protocol designed within the framework of the Internet Protocol Suite. Its definition presumes an underlying and reliable transport layer protocol, and Transmission Control Protocol (TCP) is commonly used.

The problem with UDP is that it's classed as an unreliable protocol, packets may not arrive at all and they can arrive out of sequence. If designing your own protocol you could add in your own packet sequencing and acknowledgment but that's not a part of HTTP so wouldn't work with a standard web browser. There's a few options I can think of:

  • Use UDP and instead of a web browser write a PC or phone app that sends a request to the temperature sensor for data that it can respond to. You can just retry if the packet goes astray and for a simple temerature reading the packet sequence shouldn't matter.

  • Do something like the above on your PIC but use a PC or embedded Linux board like a Raspberry Pi with a full TCP/IP stack to serve the latest temperature reading as a web page. You could have a background process to periodically poll the latest reading from the device for display.

  • Put a TCP/IP stack on the PIC along with something to directly respond to the HTTP GET requests. If you're using a PIC18 or better Microchip have a free TCP/IP Stack for PIC18, PIC24, dsPIC & PIC32 and while I haven't used it personally it does include a ENC28J60 driver.

There's a fairly good (although old) book called TCP/IP Lean that goes into detail on rolling your own TCP stack by taking a few shortcuts so it can fit in the smaller memory footprint of devices like a PIC16. That's pretty heavy going though so I think your best shot is likely to be using a PIC18 with a decent amount of FLASH / RAM and using the Microchip TCP/IP stack. There seem to be quite a few tutorials and YouTube videos on using it along with the ENC28J60.

Related Topic