Showing posts with label #homeautomation. Show all posts
Showing posts with label #homeautomation. Show all posts

Sunday, July 12, 2015

Querying the Census blockchain for wallets




The local instance of Census keeps the state of the coinbase (database of who owns what) itself in a local database. When new system is brought up – it ends up 'replaying' most of the transactions of the blockchain to get to a current state of the network. Most of the churn as your system downloads the blockchain is a complete reaudit of all the transactions – it doesn't need to challenge the older transactions with a large number of confirmations, but it still does top level validations and block signature checks just to make sure that the node isn't being fed fake data from the peer.

It still would be possible to create a malicious node that periodically sends bad transactions out on the network – but these will not poison the other systems since they'll eventually be purged. It's expected that bad data will get onto the network – stuff happens and the protocol is made to recover. There are work items for the core dev team to eventually enable the concept of 'fame' – so that a user or organization on the network can be vouched for by other well known users and issues such as data errors and poor quality items can be logged permanently to the network. For now though, if you use the normal distribution you'll be connected to the Foundation node or to another random well known node by default.

Okay, that was a lot of preamble – so now to create a quick sample program to query the local coinbase.

__author__ = 'lpreimesberger'
import censusprotocollib
import json
print "Hello world!  I'm trying to query the blockchain server on this host!"
wallet_address = raw_input( "which wallet to look for? : ")
print censusprotocollib.get_wallet("localhost", wallet_address )
Yeah, I'm not a Python guru, but that's good enough. All it does is ask for a wallet from the node on the local system. That's pretty cool – now to ask for random stuff from it:

$ python testwalletquery.py
Hello world! I'm trying to query the blockchain server on this host!
which wallet to look for? : random_wallet
Warning - server has responded with error code 400
{"result":"abend-malformed-address","warning":"Server saw: random_wallet"}

Hmm – we're not asking for the right format obviously. The Census Protocol uses Bitcoin formatted addresses – originally it tried to make an obviously 'new' format, but the current ECDSA public key to address format is pretty damn good and is hard to improve on. The format is shown really well on this diagram from https://en.bitcoin.it/wiki/File:PubKeyToAddr.png.




Altcoins use this same format and just change the network ID byte to some random, screwy number. The data is so different in Census it didn't seem there was any need to choose something new.

Okay, let's look for the sample address from the Bitcoin wiki...

$ python testwalletquery.py
Hello world! I'm trying to query the blockchain server on this host!
which wallet to look for? : 3J98t1WpEZ73CNmQviecrnyiWrnqRhWNLy
Warning - server has responded with error code 400
{"result":"abend-invalid-to"}

Well, that's better at least. We can tell it wasn't a good call from the HTTP response code of 400, and the optional return data says why. Looking at the response, it's the defined result code for 'not found'. Unless by some miracle somebody has managed to reserve that address – which is nearly impossible (stay tuned for more on this later). Fortunately for debug installs – there's a defined 'fake' Foundation account of 1Goo8Lf1sVEa12npNziCncVGDEoDuw1yEL (as of current builds at least – check the docs). Let's try that:

$ python testwalletquery.py
Hello world! I'm trying to query the blockchain server on this host!
which wallet to look for? : 1Goo8Lf1sVEa12npNziCncVGDEoDuw1yEL
[{"_id":"556e670c311f7416b2d6fc58","item_type":"wallet","txid":"0","version":1,"source":"1Goo8Lf1sVEa12npNziCncVGDEoDuw1yEL","balance":4000000000025,"created":"0","signature":"","block_in":"0","rsa_keys":[]}]


That wallet is missing a lot of the optional and more useful data real wallets have, but we'll see that next.

Friday, April 24, 2015

OMG ALEXA IS DEAD - Amazon Echo first experiences


Not surprising - first thing to know is that my Echo died in the first 24 hours of use.  I tell everyone that Thor bored her to death.


Alexa is dumb as hell.  If you are used to talking to the Google AI on your phone you are going to be sadly disappointed.  She can answer strangely specific questions like "Where is Marfa?" and "What is Taylor Swift's net worth?" with ease, but she seems to not understand a bunch of really basic queries.  This is a really new device and Amazon doesn't have the software driving it that Google has, so it's not a big disappointment, but if you want to impress your friends you need to be very careful what you ask her.  You can have her say almost anything with "Alexa - Simon says..."



Amazon music is also really hard to use - you need to move music to your 'playlist' even though it's free with prime.  So if you ask for "Play Katy Perry" you'll be treated to a 15 second sample of Juicy J ruining "Dark Horse" without messing with your Amazon account to 'add' the songs.  If I ask Google play to play something it, well - just plays it.

Most hilariously - Amazon made Alexa always speak in a G-rated lexicon.  You can't make her say anything worse than Yosemite Sam might, and she won't parrot anything she doesn't understand either, so creative Urban Dictionary attempts won't work either.  I can see what she's coded this way for first release.  But it's still funny.  She'll beep out anything that sounds beyond the pale.  Disappointing to the kids.  ^^

Although I sound all negative - this is a really nice device.  Sound is amazing, and the voice recognition and pick up is amazing.  I could talk to her anywhere downstairs within earshot and she would answer.  The sound quality is probably Bose level, even though it's a single speaker.  This thing just needs the software written for it.  I asked for access to the restricted SDK for it - but Amazon probably Googled me and choose to not answer so far.  Price of being an extremely minor net celebrity.  :-P

Amazon is mailing me a replacement - more when it appears at the house.

Sunday, February 22, 2015

Hue and cry, villain, go! Philips Hue in my home automation system



Okay, I didn't actually buy the Hue, but the Lux.  I don't need rave lights in my house.  Shakespeare quotes make the blog more classy is all.  :-)



The Lux is a wireless bulb that's more than a little pricey.  Really for the cost of this thing you can get a good quality LED build and a Z-Wave switch to control it.  The only real advantage of this is that the bulb is dimmable (most of the cheaper Z-Wave switches don't support dimming) and it's a decent option where you can't get the fatter smart switches installed.  There's no way that I could get a Z-Wave switch installed into a few of the outlets in the house just because of the tangle of connections in there, so I got some of these for those areas.

Installing it is easy - you need the smartphone app installed and you just mash the big button on the top of the hub to make it findable.   The kits all come with the hub, or you can snag one off eBay (the kits are a bit cheaper than buying the parts, so there are a lot of extra hubs out there) .  You hit the same button to chain it to the SmartThings hub.



The troublesome switches now have Lux bulbs and are happily turning off and on through the SmartThings switch automatically.

What sucks about this is that if somebody forgets and turns off the wall switch, the automation is broken since the bulb is 'dead' by that point.  Also it's expensive.  Z-Wave is cheaper for a big house by a huge margin.

I think the only time this would make sense is if you have a few unreplacable switches (like me) or if you are renting.  For an apartment this is awesome - you could replace the 4-5 bulbs in your place and completely automate the lights using your smartphone.  The Hue does support basic rules so you could get by just with the bulbs and the 'free' hub.  For a onesy-twosy case I found a cheaper option that I'll talk about later.  I sort of regret buying these bulbs now, but they're not a bad option.  There's just a better one if you own and already have something like SmartThings.


Wednesday, February 18, 2015

Home Automation #2 - SmartThings



Like I mentioned before, my old GE XT alarm system is getting pretty old - a lot of things don't work right with it and it's sort of flaky anyway.  As an alarm it's awesome but the Z Wave seems a bit challenged.

I did some research and found what seems to be the best deal for somebody who doesn't want to futz around with Raspberry Pi and doing everything themselves: SmartThings hub.

It's cheap, works okay, and does a pretty good job.  Like everything else though, there's a downside.

It's all cloud-based, so everything ends up being processed on their AWS instance.  Normally this is awesome - everything works the same everywhere and it's all good.  I have found so far though that the back end will sometimes (and judging by the support log, pretty often), suffer rolling capacity problems as all of the millions of devices being controlled turn on or off.  After I got my hub, I thought it was broken for hours just because the service was busy enough nothing seemed to be happening.

Once it settled down though, it's working pretty well.  Everything needs to be done from the Android/iOS app for basic operations.  It's pretty simple - you turn on the Z Wave and hit 'add' on the app and it finds it.  My Hue hub worked just as easily.  Being a group of nerds though - this is too boring.  Which is why SmartThings has...


An IDE.  There's a built-in support for Groovy, which is an unlovable version of the Pascal of the new millennium, Java.  It's easy to write and pretty much anyone who managed to slog through a high school computer science course in the past 10 years can write it easily.  So you can make a 'driver' for any random device that you happen to have, and as long as the SmartThings AWS or the local box can talk to your device or gadget somehow, you are good.  Which is really nice - and if you have some hardware ability you could make all sorts of crazy crap.  Anything that can talk REST can be plugged in, so you could make an automated dog house or whatever you want and it will just plug in, and you can share the code with everyone,

Judging by the forums, there's a big group of people making all sorts of gadgets that plug into this API.  Seems like a good buy so far - but as always I'll complain bitterly if things start to look otherwise.  :-)