Showing posts with label IPv6. Show all posts
Showing posts with label IPv6. Show all posts

Sunday, November 20, 2016

IPv6, Arduino, and temperature

Referring to what I learned last time, I installed the SparkFun library for the HTU21D. Then I did a simple mash-up of MiniHTTPServer and SparkFun_HTU21D_Demo, and it worked on the first try. I think I spent so much time starting two years ago being frustrated with the uIP library that I guess I don't expect Arduino to be simple, or even to work. However, I can now read temperature and humidity over IPv6 for around $25 from eBay, now that I found a working IPv6 (single-stack) library in EtherSia. I'm not complaining, but it just feels anticlimactic after all those months of arguing with the first Ethernet library to have the second Ethernet library work right away with minimal effort.

Lesson (re)learned: Always use the right tool for the job.

For future reference, this sketch would not work with an Arduino with less memory than the Nano v3; it needs that 2kB of SRAM. My hardware is HTU21D for temperature and humidity, NanoShield and EtherSia for IPv6 Ethernet, and Arduino Nano v3.

My code with EtherSia_ENC28J60:
Sketch uses 12,162 bytes (39%) of program storage space. Maximum is 30,720 bytes.
Global variables use 1,263 bytes (61%) of dynamic memory, leaving 785 bytes for local variables. Maximum is 2,048 bytes.

My code, but claiming EtherSia_W5100:
Sketch uses 11,864 bytes (38%) of program storage space. Maximum is 30,720 bytes.
Global variables use 1,259 bytes (61%) of dynamic memory, leaving 789 bytes for local variables. Maximum is 2,048 bytes.

SparkFun_HTU21D_Demo:
Sketch uses 5,656 bytes (18%) of program storage space. Maximum is 30,720 bytes.
Global variables use 460 bytes (22%) of dynamic memory, leaving 1,588 bytes for local variables. Maximum is 2,048 bytes.

Packet Printer (EtherSia_ENC28J60):
Sketch uses 7,406 bytes (24%) of program storage space. Maximum is 30,720 bytes.
Global variables use 1,053 bytes (51%) of dynamic memory, leaving 995 bytes for local variables. Maximum is 2,048 bytes.

Mini HTTP Server (EtherSia_W5100):
Sketch uses 8,112 bytes (26%) of program storage space. Maximum is 30,720 bytes.
Global variables use 1,025 bytes (50%) of dynamic memory, leaving 1,023 bytes for local variables. Maximum is 2,048 bytes.

Saturday, November 19, 2016

Arduino Nano with IPv6

I haven't touched my Arduino Nanos in a while because they didn't do IPv6 with the arduino_uip library I thought would work. However, I poked around again, and found EtherSia, so I thought I would give it a try. In the intervening time, I have switched from Mac to Linux for my daily driver.

I went to the Arduino Getting Started page, and downloaded the latest version of the IDE for Linux. I connected my Nano v3 that has the FTDI controller, so I selected Tools (menu) > Board > Arduino Nano and Tools > Port > /dev/ttyUSB0. The software selected Tools > Processor > ATmega328 automatically (which is correct for the Nano v3, but not what the hardware-specific page says to expect). I selected the "Blink" sketch (the hardware equivalent of "Hello, World!", from File (menu) > Examples > 01.Basics > Blink), clicked on Verify, clicked on Upload, and my Arduino Nano is blinking at me.

The relevant output line from lsusb for me was:

Bus 003 Device 047: ID 0403:6001 Future Technology Devices International, Ltd FT232 USB-Serial (UART) IC

When I run Tools > Get Board Info, I get
BN: Unknown board
VID: 0403
PID: 6001
SN: Upload any sketch to obtain it

No drivers were downloaded; it just worked. Despite knowing that I should quit while I'm ahead (so I can have dinner at a reasonable time), I wanted to try IPv6 from EtherSia! I went to Sketch (menu) > Include Library > Manage Libraries. I put "ethersia" in the Search box, it showed up, I clicked on Install next to the (most recent) version number, and that was just too easy. File > Examples > EtherSia > Minimal. I knew I would want it, so I brought up Tools > Serial Monitor as well. I switched it to 38400 baud (as mentioned in the sketch), and again it just works! I could even ping6 it!

Now I just need to see how it feels about reporting temperature and humidity from HTU21D over IPv6 into my monitoring. That can wait until after dinner!

Monday, November 24, 2014

Arduino Libraries

Update 2016-11-21: Since this post has many views, I want to point out that Arduino libraries are easier to install since IDE 1.6.2 (see these directions), and that EtherSia is my Arduino Ethernet library of choice because it supports IPv6 (single-stack) as well as the ENC28J60, W5500, and W5100 Ethernet controllers, and it's simple to change the Chip Select pin.

The next baby step with my Arduino is to load libraries into the IDE. (Yes, baby steps. It's easier for me to do in a short time that isn't as busy, and it's less likely that I'll get frustrated.) The directions to load Arduino libraries look easy enough. (Adafruit, Installing a Library on Mac OS X)

The library for the HTU21D is linked with the directions, another easy step.

And then, despite trying to keep it simple, I thought that first library was so easy, let me add the library for the ENC28J60 Ethernet. Alas, that was a rabbit hole! Here is my saga.

ENC28J60 and Arduino: a history, with an eye to IPv6 support

My journey starts here with Reflective Heat:

The official Arduino Ethernet Shield is based on the WizNet 5100 chip, which implements the IPv4 protocol stack in silicon. As a consequence, the Arduino Ethernet Shield cannot be used to implement an IPv6 stack.

Most people use the ENC28J60 in place of the WizNet 5100, either for its low cost, or because I wanted IPv6 support. And now I step through a littered history.

EtherCard is a driver for the ENC28J60 chip, compatible with Arduino IDE, from Jean-Claude Wippler. Adapted and extended from code written by Guido Socher and Pascal Stang ... but I don't see IPv6!

Back to Reflective Heat. The RHT IPv6 library for Arduino is based on the work of Pascal Stang, Xing Yu, and Guido Socher for EtherShield and IPv6EtherShield from Günther Hoelzl. And I note:

The earlier ipv6ethershield developed by Guenther Hoelzl was tested but found to be unstable and would not compile on the most recent versions of the Arduino Integrated Development Environment (IDE).
However, I'm a bit nervous about the RHT offering because it only discusses Arduino UNO and Mega, and I have the Nano. So I thought I'd keep looking. Apparently I don't know enough to stay away from rabbit holes!

Hey, I found a list of Arduino IPv6 library choices and Telecom Bretagne is newer! but I don't want a wireless sensor network because wireless isn't as reliable as wired Ethernet. There are directions but for wireless, so I continue to look.

I found a blog with a whole category for Arduino and this Ethernet! but no IPv6 when I searched the blog.

So once again, I found myself back at the beginning, reading about Contiki's μIPv6 stack ported for 1-wire (original site appears to be offline now), but wrong microcontroller and wrong sensor family. However, μIP will appear again, with better luck next time.

The first two libraries at Tweaking4All also lack visible IPv6 support, but discuss the same problem of having a Nano instead of an UNO or a Mega (same concern I had with RHT!). The first set is ETHER_28J60 + EtherShield (from Jose Muanis Castro; mentioned by RHT); the second one is EtherCard (mentioned above). However, the third library looks like a winner! Do I see a nod to μIP? ... drumroll please ...

UIPEthernet has some IPv6! although with a gotcha noted. But I'm reminding myself that my small goal tonight is to load libraries, just the libraries, and not to discover what might be broken later. There are examples to test first!

There are some posts about which CS (chip select) pin to use for various configurations. I like this post because it shows where to change the underlying code if you don't want to re-wire.

Tuesday, January 15, 2013

The Five Stages of IPv6

I had a note to myself to write The Five Stages of IPv6 but The Networking Nerd beat me to it. Since everyone I've encountered first approaches IPv6 with a serious case of denial, it's an obvious lead-in to find the parallels to the Kübler-Ross model.
  1. Denial: no, I don't need IPv6. Sorry, but yes, yes you do.
  2. Anger: NO, I DON'T NEED IPv6!!! Sorry, but yes, yes you do.
  3. Bargaining: can some other software or hardware do IPv6 translation for me? Load balancers like our F5 units can do it for you, but native is faster and you control it. And NAT is just plain bad, bad, bad. example
  4. Depression: there's too much to do! Start somewhere. Personally, I discovered that it was much easier than I thought. example
  5. Acceptance: now what? Start somewhere!

Wednesday, September 7, 2011

IPv6 and Solaris 9

Since static IPv6 on Solaris 9 wasn't fun enough on its own, it turns out that my Solaris 9 servers start losing a lot of IPv6 packets after a reboot. The problem appears to be in.ndpd (what should be the IPv6 neighbor discovery protocol daemon, but appears primarily to be IPv6 routing instead), and syslog reports in.ndpd[PID]: [ID 302683 daemon.error] router_add_k: RTM_ADD (interface bge0): Network is unreachable RTM_ADD every 1 to 5 minutes.

The fix is to shut down IPv6 (it's not working anyway, so go ahead) and then restore IPv6; the only difference is that in.ndpd isn't running. However, just TERMinating in.ndpd isn't enough for IPv6 traffic to flow freely. Try this instead:

# kill in.ndpd

ps -ef | grep ndp

sudo kill -TERM 11292

# bring down the IPv6 interfaces

sudo ifconfig -a6

sudo ifconfig bge0:1 inet6 down unplumb

sudo ifconfig bge0 inet6 down unplumb

sudo ifconfig lo0 inet6 down unplumb

# flush IPv6 routes

sudo route flush -inet6

# verify that IPv6 is gone

sudo ifconfig -a6

netstat -nr

# restore IPv6 interfaces

sudo ifconfig lo0 inet6 plumb up

sudo ifconfig bge0 inet6 plumb up

sudo ifconfig bge0:1 inet6 plumb up your:ipv6:address::here/64

# verify interfaces

sudo ifconfig -a6

sudo ifconfig -a

# restore default IPv6 route

sudo route add -inet6 default your:ipv6:default:router::here

# verify route table

netstat -nr

I'm trying to stay off my diatribe soap box here, but I'm happy that Solaris 9 will be replaced with RHEL 6 in the coming months.

Thursday, August 25, 2011

Static IPv6 on Solaris 10

I tried to avoid it since I'm retiring these Solaris boxes soon, but I had to put static IPv6 on Solaris 10 so I could troubleshoot. So here's how to do it, and it's not quite the same as Solaris 9.

First, get your baseline.

sudo ifconfig -a6

sudo ifconfig -a

netstat -nr

Start with loopback, the easy one.

cd /etc

sudo touch hostname6.lo0

sudo ifconfig lo0 inet6 plumb up

Move on to an actual interface, changing eri0 to your interface as needed. This is a change from the Solaris 9 approach!

sudo vi hostname6.eri0

This time, the /etc/hostname6.eri0 file should contain 'addif ipv6:addr:ess/64 up' – not just the IPv6 address/prefix, but the extra directives as well.

Now make it so!

sudo ifconfig eri0 inet6 plumb up

sudo ifconfig eri0:1 inet6 plumb

sudo ifconfig eri0:1 inet6 ipv6:host:addy/64 up

Add a route to the default router, and put its address in that file to survive reboots.

sudo route add -inet6 default ipv6:rtr:addy

sudo vi /etc/defaultrouter6

You'll want ndp running too.

sudo /usr/lib/inet/in.ndpd -a

Check your work against your baseline.

sudo ifconfig -a6

sudo ifconfig -a

netstat -nr

OK! That seems to work for now.

Wednesday, June 8, 2011

static IPv6 on Solaris 9

We use static IP addresses on our name servers, and I wanted IPv6 support on our public (and publicized) DNS too.

Doing this on Linux is straightforward and very similar to IPv4, as it should be, and you shouldn't have any trouble finding that information.

But IPv6 on Solaris, let alone Solaris 9, let alone static instead of SLAAC? Not as easy to find or do. Argh! I wasted a whole day on this, although I suppose it wasn't a wasted day since it accelerated my plan to eradicate SPARC and Solaris. (Uniformity is easier to manage.) So here's how you do it.

First, check for any existing IPv6.

sudo ifconfig -a6

While we're here, see what we've got (baseline).

sudo ifconfig -a

Since we'll need to add an IPv6 gateway, baseline the routing table too.

sudo netstat -nr

OK, baseline data collection done!

Start with an easy win, adding reboot-safe ::1 IPv6 localhost.

sudo touch /etc/hostname6.lo0

Bring up ::1. Don't forget, Solaris has that concept of plumbing the interface before it will come up.

sudo ifconfig lo0 inet6 plumb up

Depending on your interface name(s), replace bge0 with the correct interface for your system. First, tell the interface to support IPv6.

sudo ifconfig bge0 inet6 plumb up

Now you have to create a virtual interface for the IPv6 address (and yes, the address types co-exist on RHEL and Mac OS X) and bring it up. Since this is a static IPv6 address for a server, drop it in here.

sudo ifconfig bge0:1 inet6 plumb up your:ipv6:address:here

Now make it reboot-safe by putting the IPv6 address in the file /etc/hostaname6.interface.

sudo vi /etc/hostname6.bge0 # add the IPv6 addr

Not quite done! If this is a routed address, the Solaris box will need an IPv6 gateway too.

sudo route add -inet6 default your:ipv6:gateway:address

Make that reboot-safe too, by adding just the IPv6 router interface to /etc/defaultrouter6 too.

Make sure the updates look correct.

sudo ifconfig -a6

sudo ifconfig -a

netstat -nr

If you can ping6 your IPv6 gateway and IPv6 hosts outside your VLAN, it works! And it's not hard once you know what to do.

Just for reference, here's SLAAC IPv6 for Solaris 9 too; update with the right interface name from ifconfig -a as needed. Do the same baseline checks first! Then ...

sudo cp /etc/hostname.eri0 /etc/hostname6.eri0

sudo ifconfig eri0 inet6 plumb up

The RA should take care of IPv6 address prefix and routing for you.

Tuesday, June 7, 2011

World IPv6 Day!

World IPv6 Day starts in just a few minutes!!! And just in time, here's an IPv6 cupcake wrapper as an SVG file for your electronic cutter (and Sure Cuts A Lot or Makes The Cut or other software).

Friday, May 13, 2011

IPv6 DNS

We're starting down the path towards IPv6, and it looked like the first real task for me was to add IPv6 to an existing DNS server. Fortunately, with all the interruptions this morning, it turned out to be an easy task (and I had backup). I started on a name server that's maintained like all the others, running ISC bind like all the others, but hasn't been publicized so I could blow it up if needed.

First, make sure this server has an IPv6 address so it can serve DNS on that address so you can test it.

Then go to the options section of named.conf to add the following line:

listen-on-v6 { any; };

I already had a few AAAA records in our DNS, so I didn't have to add one to test. Restart named, and test it with a command like host -6 -t aaaa pickanipv6hostname ::1 to be sure it returns the IPv6 address for pickanipv6hostname. The host -6 part sends the request over IPv6, the -t aaaa requests just the AAAA type record, and ::1 uses the IPv6 localhost connection to that name server but you could use any other valid IPv6 address.

Here's a simpler example using host to retrieve an IPv6 address.

$ host -t aaaa ipv6.he.net

ipv6.he.net has IPv6 address 2001:470:0:64::2

Since I was already messing around in named.conf, I added our IPv6 space to the internal ACL. I didn't add link-local or ULA ranges since the link-locals won’t leave their VLAN, and we’re not using ULA (yet?) although that’s a clear range that can’t be routed on the Internet.

Although the DNS side was easy, I did hit two problems related to IPv6. The first was that this server couldn't leave its VLAN via IPv6; that was fixed by alerting the router guy who brought up OSPFv3. I could ping my gateway, but an IPv6 host in another VLAN couldn't ping that gateway. The other problem was that my ip6tables didn't allow DNS, and that's most easily fixed with something like ufw to make ip6tables allow what services iptables allows. So, like I said, I did it in an afternoon, and it really wasn't hard.