The Learning Curve: Apple iPhone

I like to challenge myself when I can, and go a different direction with software or hardware than I’m used to. So this week, I broke from my decade-long Android trance and picked up an iPhone 7 Plus instead. Even Tina decided to make the switch. So we’re purely an iPhone family now.

As a former Android app developer, I felt just a bit more comfortable with an Android in my pocket, since I always had the option to code up anything that I need. However, it’s been years since I needed to write any code for Android, so I was inclined to try something new. It’s never good for an engineer to get complacent with their environment, so the switch sets the stage for another era of personal innovation for me.

So far, there have been a few trying moments while learning the differences, but it hasn’t been nearly as bad as I expected.

Pain Points

The biggest aggravation so far has been integrating the phones with Home Assistant‘s presence detection. I’ve been using the Nmap presence detection that’s built into HA, so I didn’t have install a third-party app on my phone. However, the iPhone’s visibility to HA is intermittent, at best. Of course, it’s possible that the iPhone is dropping from the WIFI network also. But that seems unlikely, given that I have multiple access points and a strong WIFI signal throughout my home. It’s a bit irritating for all the lights to go out while you’re cooking dinner, when both phones drop off of HA. I’ve had to temporarily disable some of HA’s automations until I can figure this out.

The fingerprint authentication method is a nice attempt at biometric security, but I have two issues. First, it doesn’t work many times for me. I inputted both of my thumbprints, and it fails to recognize either at times. Other times it works great, and it’s super convenient. My second issue – is it actually secure? I’ve been afraid to Google the answer, but one of these days I will.

Big Plusses

Wow, the camera. The multi-rear-facing-camera setup on the 7 Plus is impressive. The “live photos” are really rad also. But is it really the camera hardware that’s better, or is it the integration of software that works some post-processing magic on the images? I’m not convinced that software isn’t the culprit behind the remarkable images.

My previous Android, the Droid Turbo, was also an impressive machine. It never really glitched on me, the GPS worked perfect every time (contrary to my experiences with prior Samsung phones), and it was quite fast after fully booted. The iPhone, however, seems just a tad bit tighter in all those respects – just slightly, but I would definitely give it the edge.

I was initially concerned that there would be some software gaps, but every app I need has been ready and waiting for me on the app store. In fact, it seems like there is actually better app support on the iPhone, which surprised me.

AirPlay and AirDrop have proven much nicer, since I have all Apple hardware everywhere else. It casts nicely to my AppleTV and syncs quickly with my MacBook.

The Verdict

I can’t make assumptions about anyone else’s comfort levels or loyalties, and it’s too soon to tell what my long term opinion will be. However, at first glance, I say try it out if you’re thinking about switching. If you hate it, you’ll always have the opportunity to switch back in two years. And for the interim, it’s a totally usable phone.

Alexa + AWS Lambda Hello World in Javascript

Here is the Javascript version of my earlier tutorial Hello World in AWS Lambda + Amazon Alexa:

'use strict';

function buildResponsePayload( title, output, repromptText, shouldEndSession ) {
	return {
		outputSpeech: {
			type: 'PlainText',
			text: output
		},
		card: {
			type: 'Simple',
			title: 'alexaHelloWorld - ' + title,
			content: 'alexaHelloWorld - ' + output
		},
		reprompt: {
			outputSpeech: {
				type: 'PlainText',
				text: repromptText,
			},
		},
		shouldEndSession,
	};
}

function buildResponse( sessionAtts, speechResponse ) {
	return {
		version: '1.0',
		sessionAtts,
		response: speechResponse,
	};
}

function sayHelloWorld( callback ) {
	const sessionAtts = {};
	const cardTitle = 'alexaHelloWorld';
	const textOutput = 'Hello Javascript World';
	const shouldEndSession = false;

	callback( sessionAtts, buildResponsePayload( cardTitle, textOutput, textOutput, shouldEndSession ) );
}

exports.handler = ( event, context, callback ) => {
	try {
		sayHelloWorld( ( sessionAtts, speechResponse ) => {
			callback( null, buildResponse( sessionAtts, speechResponse ) );
		} );
	} catch( e ) {
		callback( e );
	}
};

Enjoy!

Alexa + AWS Lambda Hello World in Python

I recently began to fool around with integrating Amazon Alexa with my Home Assistant install in a custom manner. By default, you can set up an emulated Hue in the HA configuration which allows you to toggle lights, but I wanted to do more – which means I had to build my own custom Alexa skills.

It’s amazing to me, that after hours and hours of research, I was unable to find a single solid “Hello World” tutorial online. Sure, there are plenty of tutorials, but they’re all fairly complex, or contain loads of code or information that I didn’t need. When developing in unfamiliar territory, I usually like to start with a simple “Hello World”. Below is an AWS Lambda function that you can use to echo “Hello World” through your Alexa or Echo Dot.

from __future__ import print_function

def build_response_payload( title, output, reprompt_text, should_end_session ):
	return {
		'outputSpeech': {
			'type': 'PlainText',
			'text': output
		},
		'card': {
			'type': 'Simple',
			'title': "alexaHelloWorld - " + title,
			'content': "alexaHelloWorld - " + output
		},
		'reprompt': {
			'outputSpeech': {
				'type': 'PlainText',
				'text': reprompt_text
			}
		},
		'shouldEndSession': should_end_session
	}

def build_response( session_attributes, speechlet_response ):
	return {
		'version': '1.0',
		'sessionAttributes': session_attributes,
		'response': speechlet_response
	}

def say_hello_world():
	session_attributes = {}
	card_title = "Hello World"
	speech_output = "Hello World"
	should_end_session = True
	return build_response( session_attributes, build_response_payload( card_title, speech_output, speech_output, should_end_session ) )

def lambda_handler( event, context ):
	return say_hello_world()

Here are a few pointers to get you started on your journey:
– Paste this into the inline editor in new AWS Lambda function
– Select “Python 2.7” and set the handler to lambda_function.lambda_handler
– Create a custom role and use the default options
– Set up the Lambda function and the Alexa skill pretty much how every other tutorial on the web tells you to
– The “Test” button in AWS Lambda will report errors. You should instead test directly from Alexa Skills in the AWS Developer Console. This is a little bit unintuitive and I’m not sure why it is this way. But test attempts from Lambda DO fail every time for me. I’ll update if I figure out why.

Since I typically prefer JS over Python, I’m going to do up another Hello World tutorial in Lambda Node.js shortly, this is just what I happened to get working first. I hope you can make some use of it. Enjoy!