Porting the ethernet library from Arduino

I find myself in need of a wired ethernet connection. I want to stay on the Particle platform because of the upcoming Electron. I’m attempting to grab data from an embedded system through a web interface and then relay it to my database for analysis etc.

I have acquired a Wiznet W5100 breakout that communicates via SPI. Physical connection was easy. The board is communicating with the network - I can see the link and rx/tx lights going.

I’ve tried my hand at bringing over the Arduino library. With guidance from here I made some headway. Every time I tried compiling I was missing another #include file. After tracking down about 5 additional files I had everything I needed.

Now I’m stuck. Getting tons of compile errors. Also doesn’t help that I’m pretty green when it comes to C++.

However I am motivated to learn. Anyone else interested in tackling this with me? Or have any guidance?

@fishstickjesus, if you do a forum search, you'll see this topic comes up a few times. For example:

The original idea was to use ethernet for the Cloud functions but that's not what you are doing I believe. What are you building on - web IDE, Particle DEV or local compile? If you post your code (on github or dropbox for example), I can take you look and give you guidance.

Thanks @peekay123. I did see the other threads on the topic but most seem to be stalled.

I will continue cleaning up what I know is wrong (have to change how the SPI transactions are handled). Then I’ll post it up.

PS - If your profile is any indication, it’s nice to deal with another Canuck!

@peekay123, I am Canadian eh! Located in our beautiful nation’s capital :stuck_out_tongue:

1 Like

Greetings from the grey & rainy east coast! Help me get this sorted and I’ll send you a lobster :smile:

I’ve put everything I have up at Github. Please go easy on me - I’m a javascript man living in a C++ world. First foray into Github as well.

EDIT: Forgot to answer your other question - I was using Particle Dev.

1 Like

@fishstickjesus, I already found some “areas of concern” where porting needs to be done! I’ll let you know what I do so you can understand the porting steps. :smile:

1 Like

@peekay123 Thanks for being so kind. I’m sure finding those “areas of concern” didn’t take long!

Like I said - I’m willing to work and learn. I’m already looking forward to your feedback.

1 Like

@fishstickjesus, after reviewing the library I realize that many of the classes (IPAddress, UDP, etc) conflict with Particle classes. For the library to work, these libraries would need to be renamed. Oy!

1 Like

@peekay123 - sounds very irritating. But, since I likely have no other option, I’m willing. I will begin by going through and prefix all instances with “eth_”.

Is there a good resource for seeing the names of all resources used in the Particle classes?

@fishstickjesus, IPAdress, UDP, Stream, Print and and I think socket are conflicting. To see the Particle classes, look at the documentation or the actual firmware code from the github repo.

I’d go with @peekay123’s suggestion to look into the open source repo, since it might be quite likely that the Particle versions of standard classes (e.g. Stream, Print, IPAddress, …) do fit the bill already and you just need to comment out the redeclarations.

@ScruffR, a quick look showed enough differences that I suggest doing the renaming, at least for now. The long game would be to use the existing classes but that would require a lot more work IMO.

1 Like

@fishstickjesus, I think porting this library is important. Let me do some playing around to see if I can get some of the Particle classes playing nice.

@fishstickjesus, @ScruffR, I finished porting the Ethernet library! It only compiles on the Core via CLI for now. The IPAddress code for the Core and Photon are slightly different and I know the fix so it won’t take long to do. The code now uses the Particle IPAddress, Stream and Print classes. I had to rename the UDP class to eUDP but that was all.

There were some key files missing from the library (Client.h and Server.h) which could only be found in the base Arduino files (no libraries). @fishstickjesus, in any Particle device the SPI hardware does not manage the CS line automatically so it needs to be done in user code. I added code for the initSS, setSS and resetSS macros for the Core and Photon.

In Dns.cpp I had to change a comparison of two IPAddress types which is not handled in the Particle library. My modification may or may not work.

Otherwise, the code is ready to test! I will fix that last bit and I can post the library in a dropbox for now. Any thoughts?

3 Likes

@peekay123 - I am super excited about this! I have everything all wired up here and ready to test. Looks like I will spend some time this morning learning how to properly use the CLI so that I can give this a go.

Will the code be different for Core vs Photon?

Once I can verify that this works I would be happy to make up a guide for duplicating this setup (and acknowledging your hard work).

@fishstickjesus, there are differences between the Core and Photon code when using Particle DEV or CLI. Those differences are not there when compiling locally. Eventually, both the Core and Photon will both be based on the HAL. I am still figuring out the port for the Photon code.

Which Particle is your hadware setup with (Core or Photon)?

@peekay123 I’m currently on a Core. Still waiting on my Photon (but that’s another story).

@fishstickjesus, excellent! I will post the code once I fix all the little outstanding bits. By the time you get your Photon, the new version of the firmware will be out. Trust me, it will not only reduce frustrations but introduce some amazing new features that are worth the wait.

@peekay123, my Photon has finally arrived! Thought I’d check in and see if you had any luck with the ethernet code :smile:

@fishstickjesus, I haven’t done any more work on this library since I’ve been focused on the Photon. Checking back on it, it compiles for the Core but there are some errors on the Photon. I’ll PM you a dropbox link for what I have. :smile: