The Eric Lundgren Story: When Free isn’t Free

At this point, you’ve almost certainly heard the tale of Eric Lundgren, the electronics recycler who is now looking at spending 15 months in prison because he was duplicating freely available Windows restore discs. Of no use to anyone who doesn’t already have a licensed copy of Windows, these restore discs have little to no monetary value. In fact, as an individual, you couldn’t buy one at retail if you wanted to. The duplication of these discs would therefore seem to be a victimless crime.

Eric Lundgren

Especially when you hear what Eric wanted to do with these discs. To help extend the functional lifespan of older computers, he intended on providing these discs at low cost to those looking to refurbish Windows computers. After each machine had its operating system reinstalled, the disc would go along with the computer in hopes the new owner would be able to utilize it themselves down the road.

It all sounds innocent enough, even honorable. But a quick glance at Microsoft’s licensing arrangement is all you need to know the whole scheme runs afoul of how the Redmond giant wants their operating system installed and maintained. It may be a hard pill to swallow, but when Eric Lundgren decided to use Microsoft’s product he agreed to play by their rules. Unfortunately for him, he lost.

Continue reading “The Eric Lundgren Story: When Free isn’t Free”

Scratch-Built Ornithopter: Here’s How I Flapped My Way to Flight

One of humankind’s dreams has always been to fly like a bird. For a hacker, an achievable step along the path to that dream is to make an ornithopter — a machine which flies by flapping its wings. An RC controlled one would be wonderful, controlled flight is what everyone wants. Building a flying machine from scratch is a big enough challenge, and a better jumping-off point is to make a rubber band driven one first.

I experimented with designs which are available on the internet, to learn as much as possible, but I started from scratch in terms of material selection and dimensions. You learn a lot about flight through trial and error, and I’m happy to report that in the end I achieved a great little flyer built with a hobby knife and my own two hands. Since then I’ve been looking back on what made that project work, and it’s turned into a great article for Hackaday. Let’s dig in!

Continue reading “Scratch-Built Ornithopter: Here’s How I Flapped My Way to Flight”

Simple Ethereum Vending Machines with NodeMCU

Recently, we covered how to use the Etherscan API to query data (a wallet balance) from the Ethereum blockchain with NodeMCU. It’s a very useful method for retrieving information from a blockchain on embedded systems where storage and memory are an issue.

It has some limitations though. Most notably, it’s polling the API at some interval to retrieve information whether it has changed or not. I would like to be able to receive data more efficiently than this, and quickly enough to make simple vending machines possible. While we’ve seen videos of Bitcoin-based Red Bull vending machines before, they required an NFC card to use.

If we could receive information about Ethereum transactions quickly and reliably enough, we could build a similar vending machine without requiring an NFC card as an intermediary. Simply send to an address via some method, and receive goods!

It turns out we can do exactly that with NodeMCU using WebSocket. Like HTTP, WebSocket is a communications protocol that uses TCP connections (typically over port 80), but it allows full-duplex communication. In other words, you can establish a connection to a server, and send/receive messages without needing to poll the server.

As in the previous example, we’ll use a NodeMCU running Lua. You may wish to refer to it for compile options and information about the screen, which will be the same in this case. Unlike the previous article, you will not need an API key from Etherscan to use this service (not yet, anyway). As usual, we’ll start off by connecting to WiFi:

wifi.setmode(wifi.STATION)
wifi.setphymode(wifi.PHYMODE_B)
station_cfg={}
station_cfg.ssid="Your SSID"
station_cfg.pwd="Your Password"
station_cfg.save=true
wifi.sta.config(station_cfg)

Connecting to a server with WebSockets is easy, but since we’re not using HTTP, we’ll have to remove the https:// and replace that with ws://. (Note: not wss:// because we’ve not enabled encryption yet.)

ws:connect(‘ws://socket.etherscan.io/wshandler’)

Next, we need to report back when the connection is established as the trigger to run additional code. It will return an error code if the connection fails to be established. Handling these error codes in a sensible way is an excellent feature, but we’ll handle that later:

ws:on("connection", function(ws)
    print('got ws connection')
    end)

Now, we need to extend the above to subscribe to an Eth address, and add some new code to do something when a transaction occurs. Note that the API requires that you subscribe to an address within 60 seconds of connecting. It also states that you have to send a ping event to the server every 20 seconds to keep the connection alive, so we’ll need to set a recurring timer for that.

If you’re using ESPlorer, you can send the ping request manually by entering =ws:send('{"event": "ping"}') and pressing Send. This is a useful way to test the connection status.

The address I used seems to have frequent transactions so is reasonable for testing. Be advised though that sitting and waiting for a transaction to happen to test the code creates a slow development cycle so some patience is necessary here.

ws = websocket.createClient()
ws:on("connection", function(ws)
    print('got ws connection')
    ws:send('{"event": "txlist", "address": "0x2a65aca4d5fc5b5c859090a6c34d164135398226"}')
    end)

ws:on("receive", function(_, msg, opcode)
    print('got message:', msg, opcode)
    end)

You should see something like what follows below. The first message is a simple confirmation of connection, the second confirms your subscription to an address, and the third is what you get sent when a transaction occurs. You can subscribe to up to 30 addresses with a single connected device! Note that the data is all in JSON format, which is something we’ll take advantage of later.

got message: {"event":"welcome"} 1
got message: {"event":"subscribe-txlist", "status":"1", "message":"OK, 0x2a65aca4d5fc5b5c859090a6c34d164135398226"} 1
got message: {"event":"txlist","address":"0x2a65aca4d5fc5b5c859090a6c34d164135398226","result":[{"blockNumber":"5532531","timeStamp":"1525098009","hash":"0xe5ec497cb5b38811e8bf5db67a056a2bdd4aa9b68df5c8e8225cb300cbcfa413","nonce":"3363391","blockHash":"0xf446f77d92ed29c221e8451b8048113969ed305a7dd49177e10b422e8e2c4bda","transactionIndex":"172","from":"0x2a65aca4d5fc5b5c859090a6c34d164135398226","to":"0xec5fdfba35c01c6ad7a00085e70e8f30cd121597","value":"24418350000000000","gas":"50000","gasPrice":"4000000000","input":"0x","contractAddress":"","cumulativeGasUsed":"7896403","gasUsed":"21000","confirmations":"1"}]} 1

That’s quite a mess of transaction data, and unfortunately the datum of interest is in the ‘result’ field – which is nested JSON. In the last article, we converted simple JSON to a Lua table using the excellent sjson module. We’ll do the same here after verifying the message type is a transaction (txlist).

ws:on("receive", function(_, msg, opcode)
    print('got message:', msg, opcode)
    ok, ethdata = pcall(sjson.decode, msg)
    if ok then
        msgtype = (ethdata["event"])
        if msgtype == "txlist" then
...

The NodeMCU documentation specifically notes that nested JSON can cause out-of-memory errors. For that reason we use pcall (protected call) to contain any such errors when decoding our JSON message. Next, we extract the contents of the ‘value’ field, nested within the ‘result’ field:

if msgtype == "txlist" then
    wei = ethdata.result[1].value
    print (wei)
    eth = wei/1000000000000000000
    print (eth)
    end

It took me a few hours to figure out how to deal with nested tables, but in the end it was actually quite clean and easy — I was just being dense. Now, we need to add a basic provision to handle errors when the websocket is closed:

ws:on("close", function(_, status)
    print('connection closed', status)
    print('Reconnecting...')
    ws = nil -- required to Lua gc the websocket client
    tmr.alarm(0,4000,tmr.ALARM_SINGLE,transact) -- This reconnects after 4 seconds
end)

To wrap it all up, we encase the code in a couple of functions — first, one to establish a connection, subscribe to the right address, and notify when there is a transaction. Next we need one to display the amount of Eth transferred. Finally, we need a ‘ping’ function to call every 20 seconds or less to keep the connection alive. Overall this turned out to be more robust than expected and has yet to encounter an error. Check out the full code listing here. Note that I’ve also added a little code above to interface with a 128×32 OLED screen, the same one we used previously.

Now that it works, let’s consider im/practical applications. It’s a neat way to display Ethereum transactions in real-time, say if you do livestreaming and accept Eth donations and want them to trigger something fancy. Or, you could make a somewhat insecure vending machine. Clearly, getting a secure WebSocket up and running is the next order of business.

You could also set a timer where the length depends on the amount of Eth received. This would allow for things like public advertisements that go away for a while if someone pays a fee. (Please don’t do this!) Maybe a conference room for rent with the power controlled this way? Hackerspace membership payment? An electric bicycle that charges you for power used?

In any case, it’s not legal to use cryptocurrency as a form of payment in my country so I can’t implement any of the above examples at this time. If you’ve got a better application, please share it in the comments!

Modular Robotics: When You Want More Robots in Your Robot

While robots have been making our lives easier and our assembly lines more efficient for over half a century now, we haven’t quite cracked a Jetsons-like general purpose robot yet. Sure, Boston Dynamics and MIT have some humanoid robots that are fun to kick and knock over, but they’re far from building a world-ending Terminator automaton.

But not every robot needs to be human-shaped in order to be general purpose. Some of the more interesting designs being researched are modular robots. It’s an approach to robotics which uses smaller units that can combine into assemblies that accomplish a given task.

We’ve been immersing ourselves in topics like this one because right now the Robotics Module Challenge is the current focus of the Hackaday Prize. We’re looking for any modular designs that make it easier to build robots — motor drivers, sensor arrays, limb designs — your imagination is the limit. But self contained robot modules that themselves make up larger robots is a fascinating field that definitely fits in with this challenge. Join me for a look at where modular robots are now, and where we’d like to see them going.

Continue reading “Modular Robotics: When You Want More Robots in Your Robot”

An Ode to Belgrade

In two weeks the Hackaday Community is gathering in Belgrade for Europe’s greatest hardware con, The Hackaday Belgrade Conference — an event not to be missed — but of course the city itself is a spectacular place to visit and has the perfect feel for those who like to build electronics. Why not join us for your own geek world tour to Serbia? Here’s a few of the things you’ll want to see while in Belgrade.

Aeronautical Museum Belgrade

Aircraft, Inventor, Architecture

Belgrade is a tech center and a hidden jewel of Europe. Need proof? Fly into Belgrade, and you’ll land at Nikola Tesla Airport. Pick up a car at the airport and you’ll pass a great glass torus housing Serbia’s Museum of Aviation. Here, you’ll find aircraft from both sides of the cold war, Sabres and MiGs, Hurricanes and Messerschmitts, a quite rare Sud Caravelle, and the canopy of the only stealth bomber ever to be shot down. It’s an aviation geek’s paradise, and you haven’t even left the airport.

What else is in store for you when you visit Belgrade? For the Hackaday crowd, the most interesting bit will probably be the Nikola Tesla Museum. You might know of Nikola Tesla from a webcomic, but he’s actually the greatest inventor of all time, even more so than Elon Musk. Tesla invented radio, even though Marconi got the credit. Tesla invented radar and discovered x-rays. The only person they could find to portray a figure like Tesla in The Prestige was David Bowie. Nikola Tesla is the most iconic inventor to ever live (change my mind), and his museum is in Belgrade.

Continue reading “An Ode to Belgrade”

How to Build Anything Out of Aluminum Extrusion and 3D Printed Brackets

The real power of 3D printing is in infinite customization of parts. This becomes especially powerful when you combine 3D printing with existing materials. I have been developing a few simple tricks to make generic fasteners and printed connectors a perfect match for aluminum extrusion, via a novel twist or two on top of techniques you may already know.

Work long enough with 3D printers, and our ideas inevitably grow beyond our print volume. Depending on the nature of the project, it may be possible to divide into pieces then glue them together. But usually a larger project also places higher structural demands ill-suited to plastic.

Those of us lucky enough to have nice workshops can turn to woodworking, welding, or metal machining for larger projects. Whether you have that option or not, aluminum extrusion beams provide the structure we need to go bigger and to do it quickly. And as an added bonus, 3D printing can make using aluminum extrusion easier and cheaper.

Continue reading “How to Build Anything Out of Aluminum Extrusion and 3D Printed Brackets”

The Aluminum Wiring Fiasco

Someone who decides to build a house faces a daunting task. It’s hard enough to act as the general contractor for someone else, but when you decide to build your own house, as my parents did in the early 1970s, it’s even tougher. There are a million decisions to make in an information-poor and rapidly changing environment, and one wrong step can literally cast in stone something you’ll have to live with forever. Add in the shoestring budget that my folks had to work with, and it’s a wonder they were able to succeed as well as they did.

It was a close call in a few spots, though. I can recall my dad agonizing over the wiring for the house. It would have been far cheaper to go with aluminum wiring, with the price of copper wire having recently skyrocketed. He bit the bullet and had the electrician install copper instead, which ended up being a wise choice, as houses that had succumbed to the siren call of cheaper wiring would start burning down all over the United States soon thereafter.

What happened in the late 60s and early 70s in the residential and commercial electrical trades was an expensive and in some cases tragic lesson in failure engineering. Let’s take a look at how it all happened.

Continue reading “The Aluminum Wiring Fiasco”