there is a label on the handle namewith my name and address on it,从with到最后做整个句子的

In my previous post about
a couple of people commented that they couldn’t actually access the users information once they had linked their account.
I didn’t actually try and access any of the user information because the only user of my skill is me, and I already know my name and email address.
Nevertheless, I had a quick play with it over the weekend and here’s a simple skill to show you how to access the user’s profile information from a Python skill running in AWS Lambda.
First of all you need to make sure your skill is set up to use Login With Amazon.
I’ve covered this for Smart Home skills
but it works just the same for normal skills.
You also need to make sure your skill is configured to use the scopes “profile” and “postal_code“.
This is done in the Configuration tab in the developer console for your skill:
The Interaction Model for this skill is as follows:
"intents": [
"intent": "AMAZON.HelpIntent"
"intent": "AMAZON.CancelIntent"
"intent": "AMAZON.StopIntent"
"slots": [
"name": "Options",
"type": "Options"
"intent": "GreetIntent"
The Custom Slot type “Options” is:
First name
email address
And the Sample Utterances are:
GreetIntent Tell me my {Options}
GreetIntent What is my {Options}
And here’s the code (also on ):
#!/usr/bin/python
import requests
def build_speechlet_response(title, output, reprompt_text, should_end_session):
'outputSpeech': {
'type': 'PlainText',
'text': output
'type': 'Simple',
'title': "Greeter",
'content': output
'reprompt': {
'outputSpeech': {
'type': 'PlainText',
'text': reprompt_text
'shouldEndSession': should_end_session
def build_response(session_attributes, speechlet_response):
'version': '1.0',
'sessionAttributes': session_attributes,
'response': speechlet_response
def get_user_info(access_token):
#print access_token
amazonProfileURL = '/user/profile?access_token='
r = requests.get(url=amazonProfileURL+access_token)
if r.status_code == 200:
return r.json()
return False
def handle_end():
return build_response({}, build_speechlet_response("Session ended", "Goodbye!", "", True))
def launch_request(access_token):
session_attributes = {}
card_title = "Welcome"
if access_token is None:
speech_output = "Your user details are not available at this time.
Have you completed account linking via the Alexa app?"
reprompt_text = ""
should_end_session = True
user_details = get_user_info(access_token)
if user_details is None:
speech_output = "There was a problem getting your user details."
should_end_sesion = True
print user_details
speech_output = "Hello "+user_details['name'].split(" ")[0]+"!
I know all about you now.
We can be friends!"
reprompt_text = "What can I tell you about your user information?
First name, last name, email address or postcode?"
should_end_session = False
return build_response(session_attributes, build_speechlet_response(
card_title, speech_output, reprompt_text, should_end_session))
def intent_request(intent_request, access_token):
intent = intent_request['intent']
intent_name = intent['name']
if intent_name == "GreetIntent":
if access_token is not None:
user_details = get_user_info(access_token)
if user_details is None:
query_type = False
query_type = intent['slots']['Options']['value']
return handle_end()
if query_type == "post code":
speech_output = "Your post code is "+user_details['postal_code']+"."
elif query_type == "first name":
speech_output = "Your first name is "+user_details['name'].split(" ")[0]+"."
elif query_type == "last name":
speech_output = "Your last name is "+user_details['name'].split(" ")[1]+"."
elif query_type == "email address":
speech_output = "Your email address is "+user_details['email']+"."
elif query_type == "user id":
speech_output = "Your user id is "+user_details['user_id']+"."
speech_output = "Something went wrong.
card_title = "What I know about you"
return build_response({}, build_speechlet_response(card_title, speech_output, None, True))
if intent_name == "AMAZON.HelpIntent":
print "Help intent"
card_title = "No help available!"
speech_output = "Sorry, I can't help you."
return build_response({}, build_speechlet_response(card_title, speech_output, None, True))
if intent_name == "AMAZON.CancelIntent" or intent_name == "AMAZON.StopIntent":
card_title = "Session Ended"
speech_output = "Good bye!"
return build_response({}, build_speechlet_response(card_title, speech_output, None, True))
def lambda_handler(event, context):
print event
access_token = event['context']['System']['user']['accessToken']
access_token = None
if event['request']['type'] == "LaunchRequest":
return launch_request(access_token)
elif event['request']['type'] == "IntentRequest":
return intent_request(event['request'],access_token)
The important part is:
event['context']['System']['user']['accessToken']
Once that is available to your Lambda script then you know that the user has done the OAUTH account linking, and then you can query the Amazon APIs for the user’s info.
I’m not proud of this code, so I will tidy it up in to a better demo at some point and update this post accordingly.
Here’s a quick video of what it does:
I got a Cisco 7941 off eBay.
This is a phone which was ?400 when new (some time around 2004) but can now be picked up for about ?10.
These phones went End Of Sale in January 2010, so even if mine was one of the last phones to roll off the production line it’s still about 7 years old but it’s still working perfectly.
A testament to the good build quality of these phones, and perhaps the previous owner’s careful handling.
Since these devices are no longer supported many companies will be getting rid of them (or probably already have) so there should be some bargains to be had for phone geeks.
Q: Does the Cisco 7941 work with Asterisk?
You need to load the SIP firmware (the focus of this post) or chan-sccp (out of scope for this post but I’ll check it out at some point).
Q: Does the Cisco 7941 work with SIP?
You need to flash the correct firmware though.
Q: Is it really hard to get working?
If you’re comfortable with Linux and a few command line tools.
And assuming you already have Asterisk set up.
Q: Is a lot of the information on the web about how to set up the 7941 wrong?
There is a lot of confusion about config files (the 7940 and 7941 use different ones).
Q: Will you tell us how you got your phone to work?
However – this is what works for me.
You will need to tweak the config in places.
The steps to getting this phone working as a SIP extension on Asterisk on Ubuntu / Raspberry Pi:
Set up a TFTP Server
The phone will download it’s firmware and config via TFTP.
It needs to download it’s config on every boot, so you will always need a TFTP server running.
I think that if the TFTP server is unavailable it will just use the previous config, so it’s possible that you can get away without it, but I haven’t tried.
My recommendation is that you install .
It’s a small and full featured DNS server which also includes a DHCP & TFTP server which are easy to configure and it’s almost certainly packaged for your distro.
You should also (temporarily) disable any other DHCP servers on your local network so that dnsmasq is the only thing offering DHCP addresses.
This will simplify the process of getting the phone to find the TFTP server, since with dnsmasq it will all be automatic.
If you later re-enable your original DHCP server, say on your router, then you will need to configure it to give out the address of the dnsmasq TFTP server and disable DHCP on dnsmasq.
In my opinion, if you’re going to be running a Cisco IP phone on your network you’d be better off moving all DHCP to dnsmasq.
The full configuration of dnsmasq it’s out of scope for this doc, but in a nutshell you need these in your dnsmasq config:
Set up a DHCP range
dhcp-range=192.168.1.1,192.168.1.100,24h
Enable the TFTP server
enable-tftp
Set the TFTP path
tftp-root=/home/&your user&/tftp
(or whatever works for you)
Download the SIP Firmware from Cisco
Usually Cisco require a valid support contract before you can download anything useful from their website, but it seems that since these phones are now out of support they have offered up the firmware free of charge.
You do still need to register an account to download the files.
At the time of writing the latest version is 9.4.2 SR 3 dated 14th February 2017 – so bang up to date, even though these phones are end-of-life.
Bizarre, but good for us.
Thanks Cisco!
Follow the link to the SIP software.
You want to download the “SIP firmware files only”
Unzip that file into the root of your TFTP server (the location you set in the previous step).
You should have 8 files in there:
apps41.9-4-2ES26.sbn
dsp41.9-4-2ES26.sbn
term41.default.loads
cnu41.9-4-2ES26.sbn
jar41sip.9-4-2ES26.sbn
term61.default.loads
cvm41sip.9-4-2ES26.sbn
SIP41.9-4-2SR3-1S.loads
This is everything you need to reflash your phone to the latest SIP firmware.
Now you need to get the phone to reboot in to firmware download mode.
Flash the phone with the firmware via the TFTP server
Unplug the phone from the power.
Make sure that the network cable is still connected (unless you’re using using PoE).
Plug the power back in and hold down the # key
Eventually you will see the “line” lights start to flash orange.
It might take a couple of minutes to get to this stage, don’t give up, just keep holding down #
When the line lights are flashing type #
This will start firmware download mode.
The screen will go black for a moment and then go through the process of getting an IP address and connecting to the TFTP server
Once connected to the TFTP server the software download will start
The phone will reboot once download is complete and present you with an “Unprovisioned” message on the screen.
This is good news!
The phone firmware has now been updated.
I put together a video showing this process.
It’s not very interesting but it will give you an idea of what to expect.
The actual downloading of the firmware section has been sped up 3X.
Configure the SIP extension in Asterisk
Now you need to configure the SIP extension in Asterisk.
Do this as per any other SIP extension, but bear this important piece of information in mind:
The Cisco 7941 can only deal with 8 character passwords, so keep your SIP authentication secret to 8 characters.
While you’re in Asterisk configuration mode, take a moment to note down these bits of information as well (in Advanced SIP settings in FreePBX):
RTP Port range, start and end.
Bind Port (probably 5060)
Write the config files for the phone and upload them via the TFTP server
Please take the time to read this section fully,
this is the part that is most troublesome.
The Cisco 7941 is very picky about it’s config file and even a small mistake will stop the phone from working.
These settings are specific to the 79×1 series of phones running at least version 8.x of the firmware.
If your phone is not a 79×1 and/or is not running v9.x.x of the firmware then these settings are not for you.
Once the phone has loaded it’s firmware and booted, it will go looking for a file called SEP&PHONE MAC ADDRESS&.cnf.xml.
So if the MAC address of your phone is 11:22:33:44:55:66 then the config file needs to be named <f.xml.
This file needs to be in the root of your TFTP server.
You will see mention of a file f.xml.
If you&#8217;ve only got a few phones, don&#8217;t worry about this, you don&#8217;t need it.
So here is a config file which is about as minimal as I can make it:
&deviceProtocol&SIP&/deviceProtocol&
&sshUserId&cisco&/sshUserId&
&sshPassword&cisco&/sshPassword&
&ipAddressMode&0&/ipAddressMode&
&devicePool&
&dateTimeSetting&
&dateTemplate&D/M/Ya&/dateTemplate&
&timeZone&GMT Standard/Daylight Time&/timeZone&
&name&#IP ADDRESS OF AN NTP SERVER#&/name&
&ntpMode&Unicast&/ntpMode&
&/dateTimeSetting&
&callManagerGroup&
&member priority="0"&
&callManager&
&ethernetPhonePort&2000&/ethernetPhonePort&
&sipPort&#SIP PORT NUMBER FROM YOUR ASTERISK SERVER#&/sipPort&
&processNodeName&#IP ADDRESS OF YOUR ASTERISK SERVER#&/processNodeName&
&/callManager&
&/members&
&/callManagerGroup&
&/devicePool&
&sipProfile&
&sipProxies&
&registerWithProxy&true&/registerWithProxy&
&/sipProxies&
&sipCallFeatures&
&cnfJoinEnabled&true&/cnfJoinEnabled&
&rfc2543Hold&false&/rfc2543Hold&
&callHoldRingback&2&/callHoldRingback&
&localCfwdEnable&true&/localCfwdEnable&
&semiAttendedTransfer&true&/semiAttendedTransfer&
&anonymousCallBlock&2&/anonymousCallBlock&
&callerIdBlocking&2&/callerIdBlocking&
&dndControl&0&/dndControl&
&remoteCcEnable&true&/remoteCcEnable&
&/sipCallFeatures&
&sipStack&
&sipInviteRetx&6&/sipInviteRetx&
&sipRetx&10&/sipRetx&
&timerInviteExpires&180&/timerInviteExpires&
&timerRegisterExpires&3600&/timerRegisterExpires&
&timerRegisterDelta&5&/timerRegisterDelta&
&timerKeepAliveExpires&120&/timerKeepAliveExpires&
&timerSubscribeExpires&120&/timerSubscribeExpires&
&timerSubscribeDelta&5&/timerSubscribeDelta&
&timerT1&500&/timerT1&
&timerT2&4000&/timerT2&
&maxRedirects&70&/maxRedirects&
&remotePartyID&true&/remotePartyID&
&userInfo&None&/userInfo&
&/sipStack&
&autoAnswerTimer&1&/autoAnswerTimer&
&autoAnswerAltBehavior&false&/autoAnswerAltBehavior&
&autoAnswerOverride&true&/autoAnswerOverride&
&transferOnhookEnabled&false&/transferOnhookEnabled&
&enableVad&false&/enableVad&
&preferredCodec&g711ulaw&/preferredCodec&
&dtmfAvtPayload&101&/dtmfAvtPayload&
&dtmfDbLevel&3&/dtmfDbLevel&
&dtmfOutofBand&avt&/dtmfOutofBand&
&alwaysUsePrimeLine&false&/alwaysUsePrimeLine&
&alwaysUsePrimeLineVoiceMail&false&/alwaysUsePrimeLineVoiceMail&
&kpml&3&/kpml&
&natEnabled&false&/natEnabled&
&phoneLabel&#PHONE NAME#&/phoneLabel&
&stutterMsgWaiting&0&/stutterMsgWaiting&
&callStats&false&/callStats&
&silentPeriodBetweenCallWaitingBursts&10&/silentPeriodBetweenCallWaitingBursts&
&disableLocalSpeedDialConfig&false&/disableLocalSpeedDialConfig&
&startMediaPort&#RTP START PORT#&/startMediaPort&
&stopMediaPort&#RTP END PORT#&/stopMediaPort&
&sipLines&
&line button="1"&
&featureID&9&/featureID&
&featureLabel&#EXT NUM#&/featureLabel&
&proxy&USECALLMANAGER&/proxy&
&port&#SIP PORT#&/port&
&name&#EXT NUM#&/name&
&displayName&#EXT NAME#&/displayName&
&autoAnswer&
&autoAnswerEnabled&2&/autoAnswerEnabled&
&/autoAnswer&
&callWaiting&3&/callWaiting&
&authName&#SIP AUTH NAME#&/authName&
&authPassword&#8 CHAR PASSWORD#&/authPassword&
&sharedLine&false&/sharedLine&
&messageWaitingLampPolicy&1&/messageWaitingLampPolicy&
&messagesNumber&#VM NUM#&/messagesNumber&
&ringSettingIdle&4&/ringSettingIdle&
&ringSettingActive&5&/ringSettingActive&
&contact&#EXT NUM#&/contact&
&forwardCallInfoDisplay&
&callerName&true&/callerName&
&callerNumber&true&/callerNumber&
&redirectedNumber&false&/redirectedNumber&
&dialedNumber&true&/dialedNumber&
&/forwardCallInfoDisplay&
&line button="2"&
&featureID&9&/featureID&
&featureLabel&#EXT NUM#&/featureLabel&
&proxy&USECALLMANAGER&/proxy&
&port&#SIP PORT#&/port&
&name&#EXT NUM#&/name&
&displayName&#EXT NUM#&/displayName&
&autoAnswer&
&autoAnswerEnabled&2&/autoAnswerEnabled&
&/autoAnswer&
&callWaiting&3&/callWaiting&
&authName&#SIP AUTH NAME#&/authName&
&authPassword&#8 CHAR PASSWORD#&/authPassword&
&sharedLine&false&/sharedLine&
&messageWaitingLampPolicy&1&/messageWaitingLampPolicy&
&messagesNumber&#VM NUM#&/messagesNumber&
&ringSettingIdle&4&/ringSettingIdle&
&ringSettingActive&5&/ringSettingActive&
&contact&#EXT NUM#&/contact&
&forwardCallInfoDisplay&
&callerName&true&/callerName&
&callerNumber&true&/callerNumber&
&redirectedNumber&false&/redirectedNumber&
&dialedNumber&true&/dialedNumber&
&/forwardCallInfoDisplay&
&/sipLines&
&voipControlPort&#SIP PORT#&/voipControlPort&
&dscpForAudio&184&/dscpForAudio&
&ringSettingBusyStationPolicy&0&/ringSettingBusyStationPolicy&
&dialTemplate&dialplan.xml&/dialTemplate&
&/sipProfile&
&commonProfile&
&phonePassword&&/phonePassword&
&backgroundImageAccess&true&/backgroundImageAccess&
&callLogBlfEnabled&1&/callLogBlfEnabled&
&/commonProfile&
&loadInformation&SIP41.9-4-2SR3-1S&/loadInformation&
&vendorConfig&
&disableSpeaker&false&/disableSpeaker&
&disableSpeakerAndHeadset&false&/disableSpeakerAndHeadset&
&pcPort&0&/pcPort&
&settingsAccess&1&/settingsAccess&
&garp&0&/garp&
&voiceVlanAccess&0&/voiceVlanAccess&
&videoCapability&0&/videoCapability&
&autoSelectLineEnable&0&/autoSelectLineEnable&
&webAccess&0&/webAccess&
&spanToPCPort&1&/spanToPCPort&
&loggingDisplay&1&/loggingDisplay&
&loadServer&&/loadServer&
&sshAccess&0&/sshAccess&
&/vendorConfig&
&versionStamp&001&/versionStamp&
&networkLocale&United_Kingdom&/networkLocale&
&networkLocaleInfo&
&name&United_Kingdom&/name&
&uid&64&/uid&
&version&1.0.0.0-4&/version&
&/networkLocaleInfo&
&deviceSecurityMode&1&/deviceSecurityMode&
&authenticationURL&&/authenticationURL&
&servicesURL&&/servicesURL&
&transportLayerProtocol&2&/transportLayerProtocol&
&certHash&&/certHash&
&encrConfig&false&/encrConfig&
&dialToneSetting&2&/dialToneSetting&
Copy and paste this into a text editor and search and replace the following:
#IP ADDRESS OF AN NTP SERVER#
the IP address of an NTP server
#SIP PORT FROM YOUR ASTERISK SERVER#
the SIP port of your asterisk server is listening on.
Probably 5060
#IP ADDRESS OF YOUR ASTERISK SERVER#
the IP address of your Asterisk server
#PHONE NAME#
the text you want to appear at the top right of the phone screen
#RTP START PORT#
the RTP port range start from the previous stage
#RTP END PORT#&#8217;
the RTP port range end from the the previous stage
the Asterisk extension number as configured in the previous stage
#SIP PORT#
the SIP port of your Asterisk server.
Probably 5060
#EXT NAME#
the name you want to give this extension
#SIP AUTH NAME#
the username for the SIP extension as configured in Asterisk
#8 CHAR PASSWORD#
the password for the SIP extension as configured in Asterisk
the number you dial for Voicemail.
Probably *98
Note that this config file has two lines configured.
If you just blindly search and replace you&#8217;ll end up with two extensions configured the same.
Some comments on what some of the XML tags do:
ipAddressMode &#8211; 0 is IP v4 only. But this seems to have little effect.
registerWithProxy &#8211; true &#8211; Registers the device with Asterisk, this allows incoming calls to be sent to the phone.
If you&#8217;re getting &#8220;Unregistered&#8221; message on the screen, check you have this set.
featureId &#8211; 9 is SIP
autoAnswerEnabled &#8211; 2 &#8211; 2 seems to be &#8220;off&#8221;
webAccess &#8211; 0 &#8211; 0 is on (?!)
sshAccess -0 &#8211; ditto
versionStamp &#8211; bump this up every time you make a change.
Something like YYYMMDD001..2..3 etc
networkLocale &#8211; United_Kingdom &#8211; sets the tones to UK, see the optional extras section for more info.
transportLayerProtocol &#8211; 2 is UDP, 1 is TCP
dialToneSettings &#8211; 2 is &#8220;always use internal dialtone&#8221;.
See option extras for more info.
Edit this file as necessary and then save it to the root of your TFTP server with the filename: SEP&MAC&.cnf.xml.
If your phone MAC address was aa:bb:33:44:55:66 then the filename would be: <f.xml
Note that it&#8217;s case sensitive, letters in the MAC address should be in upper case the extensions should be in lowercase.
You can get the MAC address for the phone from the syslog on your dnsmasq server.
If your phone is still in &#8220;Unprovisioned&#8221; mode it will have been asking for this config file repeatedly.
Once you save the file you should see the phone reboot shortly afterwards.
It may download the firmware again for some reason, just leave it to get on with it.
Make a call!
If everything has worked you should see your extension listed on the right hand side of the screen near the buttons, and the name of the phone should appear at the top of the screen.
If the icon next to the line buttons is that of a phone without an x through it, then you&#8217;re probably good to go!
Press the line button and see if you get a dial tone.
If not, then check the phone logs:
Press Settings
From these logs you should be able to tell if the phone has loaded your config correctly.
Errors about &#8220;updating locale&#8221; or &#8220;no trust list installed&#8221; can be ignored.
If there is a problem with the config file itself a generic error will be listed here.
If the phone won&#8217;t load the config file the most likely reason is that there is a typo in your XML file.
Good luck finding it.
You can SSH in to the phone to get more detailed logs and debugging information, but I haven&#8217;t tried this yet.
Google is your friend.
Optional Extras
The dial plan tells the phone how to process the digits you type and when to start sending the call.
Without a dial plan the phone simply waits a period of time for you to stop typing numbers before it decides you&#8217;re done and starts the call.
By using a dial plan you can reduce the amount of time spent waiting after you&#8217;ve finished keying in the number.
Here&#8217;s an example plan I&#8217;ve edited based on this post on Phil Lavin&#8217;s blog (Thanks Phil!)
&DIALTEMPLATE&
&TEMPLATE MATCH="999" Timeout="0"/& &!-- Emergency --&
&TEMPLATE MATCH="112" Timeout="0"/& &!-- Emergency --&
&TEMPLATE MATCH="0500......" Timeout="0"/& &!-- Apparently 0500 is always 10 digits --&
&TEMPLATE MATCH="0800......" Timeout="0"/& &!-- Apparently 0800 is always 10 digits --&
&TEMPLATE MATCH="00*" Timeout="5"/& &!-- International, 00 prefixed. No fixed length --&
&TEMPLATE MATCH="0.........." Timeout="0"/& &!-- UK 11 digit, 0 prefixed --&
&TEMPLATE MATCH="26...." Timeout="0"/& &!-- My local STD numbers start 26 --&
&TEMPLATE MATCH="\*.." Timeout="0"/& &!-- Asterisk *.. codes --&
&TEMPLATE MATCH="\*98...." Timeout="0"/& &!-- Asterisk direct VM access *981234--&
&TEMPLATE MATCH="1..." Timeout="0"/& &!-- Internal numbers --&
&TEMPLATE MATCH="2..." Timeout="0"/&
&!-- Internal numbers --&
&TEMPLATE MATCH="*" Timeout="5"/& &!-- Anything else --&
&/DIALTEMPLATE&
Save this to the root of your TFTP server, named &#8220;dialplan.xml&#8221; (lowercase).
Ring tones
Everyone likes novelty ringtones.
You can find plenty of ringtones in a format which is compatible with your phone (raw format, 8000 Hz sample rate, 8 bit, ulaw, max 2 seconds).
These files need to be placed in to the root of your TFTP server.
I tried putting them in a sub-directory but it didn&#8217;t work.
Then you need to create a file called &#8220;ringlist.xml&#8221; also in the root of the server.
The format of this file is:
&CiscoIPPhoneRingList&
&DisplayName&#DISPLAY TEXT#&/DisplayName&
&FileName&#FILENAME#&/FileName&
&DisplayName&#DISPLAY TEXT#&/DisplayName&
&FileName&#FILENAME#&/FileName&
&/CiscoIPPhoneRingList&
Filenames are case sensitive.
Once you&#8217;ve save this file, copy it to &#8220;distinctiveringlist.xml&#8221; as well.
This will allow you to set ring tones for the default ringer and different rings for each line.
Dial tones
By default the 7941 will have a psuedo North American dial tone.
This is annoyingly shrill (yes, it is).
By specifying a NetworkLocale in the phone config we can get it to load a different set of informational tones from a file stored in (per the example XML above) United_Kingdom.
In the root of the TFTP server create a directory called United_Kingdom.
In this directory you need to create a file called g3-tones.xml.
Bizarrely Cisco require you to have a support contract in order to download the correct tones settings for your country, despite giving the phone firmware away for free.
Go figure.
So this means I&#8217;m not going to paste the XML here.
If you search hard enough you&#8217;ll find an example g3-tones.xml file you can use as a base.
In our phone configuration above we told the phone to always use the internal dialing tone, so this means we only need to change the idial section of the tones file.
The magic numbers are:
The phone comes with a single default wallpaper with horizontal lines on it.
This is easily replaced by your own designs with a simple PNG.
Create a directory in the root of the TFTP server called Desktops.
In here create another directory called 320x196x4.
In to this directory you need to place a &#8220;List.xml&#8221; file:
&CiscoIPPhoneImageList&
&ImageItem Image="TFTP:Desktops/320x196x4/ubuntu-tn.png"
URL="TFTP:Desktops/320x196x4/ubuntu.png"/&
&/CiscoIPPhoneImageList&
The &#8220;-tn&#8221; in the file is a smaller thumbnail version of the larger image.
The PNGs need to be sized exactly 320&#215;196 for the large and 80&#215;49 for the thumbnail.
Here&#8217;s something to get you started:
Telephone Directory
You will have noticed that the phone has a &#8220;Directories&#8221; button and a &#8220;Services&#8221; button.
I haven&#8217;t managed to add an extra phone book to the Directories button yet although I think it&#8217;s certainly possible, just that the XML file refuses to do anything.
However, I have got a phone directory working on the Services button.
In the main phone config file there is a tag for &#8220;servicesURL&#8221;.
Point this to a web server on your local network which will serve up an XML file.
For example:
&servicesURL&http://192.168.1.1/phone/directory.xml&/servicesURL&
Assuming you are using Apache 2 to serve that XML file (or it could equally be a CGI script which generates the XML dynamically from a database such as the FreePBX phone book) the format looks like this:
&CiscoIPPhoneDirectory&
&Title&Whizzy Towers&/Title&
&DirectoryEntry&
&Telephone&1500&/Telephone&
&Name&Lenny&/Name&
&/DirectoryEntry&
&DirectoryEntry&
&Telephone&1234&/Telephone&
&Name&Speaking Clock&/Name&
&/DirectoryEntry&
&/CiscoIPPhoneDirectory&
Important note:
You must tell Apache to serve those files as type &#8220;text/xml&#8220;.
&#8220;application/xml&#8221; will not work.
You can do this via your CGI script, or if you want to serve a static file add something like this to your Apache config:
&Location /phone/&
ForceType text/xml
&/Location&
Inside your VirtualHost section.
Watch /var/log/syslog on the machine running the TFTP server.
You&#8217;ll be able to see exactly what files the phone is asking for.
Bear in mind that it does ask for files it doesn&#8217;t strictly need, so don&#8217;t worry too much about file not found errors unless it&#8217;s one of the above.
Here&#8217;s a final video showing the boot up for a fully configured phone
Alexa smart home skills require you to provide
so that users can authorise a skill to access the assumed cloud service powering their lightbulbs or any number of other pointlessly connected devices.
This makes sense since OAUTH2 is a standard and secure way to grant access for users from one system to the resources of another.
However, with this come a few caveats which are potential blockers for casual skill developers like me.
If you&#8217;re writing a skill for your own personal use, with no intention of adding it to the store, you still have to have a valid and recognised SSL certificate and a whole OAUTH2 server set up somewhere.
The SSL certificate is easy enough to implement, but it&#8217;s a bit of a faff (renewing Let&#8217;s Encrypt certs, or paying for cert which needs you to deal with the certificate authorities, send in scans of your passport and other tedious red tape) but &#8211; in my opinion anyway &#8211; setting up an OAUTH server is even more of a faff.
If only there was some way to avoid having to do either of these things&#8230;.
Using &#8220;Login With Amazon&#8221; as your OAUTH provider
Since you already have an Amazon account you can use &#8220;Login With Amazon&#8221; as your skill&#8217;s OAUTH server and your normal everyday Amazon account as your credentials.
You&#8217;re only sharing your Amazon account data with yourself, and even then we can restrict it to just your login ID.
You don&#8217;t actually need to do anything with the OAUTH token once it&#8217;s returned since you&#8217;re the only user.
I mean, you could if you wanted to, but this HOWTO assumes that you&#8217;re the only user and that you don&#8217;t care about that sort of thing.
We are also going to assume that you have already created the Lambda function and the smart home skill or are familiar with how to do that.
This is a bit tricky because you can&#8217;t test your smart home skill on a real device until you&#8217;ve implemented OAUTH, and you can&#8217;t complete the OAUTH set-up until you&#8217;ve got the IDs from your Lambda function and skill.
If you haven&#8217;t written your skill yet, just create a placeholder Lambda function and smart home skill to be going on with.
Much of this information is available from the official Amazon instructions available here:. What follows is a rehash and slight reorganisation of that doc which is hopefully a bit easier to follow.
1. Create a new Login With Amazon Security Profile
From the Amazon Developer Site, go to Apps & Services -& Login With Amazon.
Click &#8220;Create a New Security Profile&#8221;.
Fill out the form along these lines:
and hit Save.
You should see a message along the lines of &#8220;Login with Amazon successfully enabled for Security Profile.&#8221;
Hover the mouse over the cog icon to the right of your new security profile and choose &#8220;Security Profile&#8221;.
Copy your &#8220;Client ID&#8221;
and &#8220;Client Secret&#8221; and paste it in to a notepad.
You&#8217;ll need this again shortly.
2. Configure your skill to use Login With Amazon
Back in the , navigate to the Configuration page for your skill.
(Click on your skill, then click on Configuration).
You need to enable &#8220;Account Linking&#8221; and this will then show the extra boxes discussed below.
In to the &#8220;Authorization URL&#8221; box you should put:
/ap/oa/?redirect_url=
and then copy the Redirect URL from further down the page and append it to the end of the Authorization URL.
For example:
/ap/oa/?redirect_url=/api/skill/link/1234ABCD1234AB
As far as I can tell Layla is for UK/Europe and Pitangui is for the US.
Use the appropriate one for you.
Also, keep a note of the redirect URL in your notepad, you will need this again later.
In to the &#8220;Client Id&#8221; box paste your client id from step 1.
You can leave &#8220;Domain List&#8221; blank for now.
For &#8220;Scope&#8221; I suggest you use:
profile:user_id
This will give your Alexa Skill access to a minimal amount of information about you from Amazon, in this case just a user_id.
That user ID is unique to your app so can&#8217;t be used by other apps or to identify that user elsewhere.
Since you don&#8217;t really have any customers for your skill, only you, there is no reason to provide access to any other information.
Further down the page you need to configure the Grant Type:
Select an &#8220;Auth Code Grant&#8221;
Set the &#8220;Access Token URI&#8221; to:
/auth/o2/token
and in to &#8220;Client Secret&#8221; paste your secret from step 1.
You must include a link to your &#8220;Privacy Policy URL&#8220;.
Since you are the only person who cares you could host a blank file somewhere, or maybe link to a Rick Astley video on YouTube?
Finally hit Save.
3. Link Login With Amazon back to your Skill
Head back to the Login With Amazon page:
Hover over the cog of your Security Profile and choose Web Settings:
In to the &#8220;Allowed Return URLs&#8221; box paste your Redirect URL from step 2 and hit save.
Login to Amazon from your skill and do the OAUTH dance
From the Alexa app on your phone navigate to your new Smart Home Skill and you see that it says &#8220;Account Linking Required&#8220;.
Click &#8220;Enable Skill&#8221; and you&#8217;ll be asked to login with your Amazon credentials:
Once you log in you should see a success message:
And you&#8217;re done.
Additional:
Here&#8217;s a post on how to read the users details from Amazon once they are linked:
I posted this to Github, but thought I would mirror it here too. You can download the code from here:
A Python library for talking to some Sony Bravia TVs, and an accompanying Alexa Skill to let you control the TV by voice. If you like that sort of thing.
These scripts make use of the excellent Requests module. You&#8217;ll need to install that first.
bravialib itself
This is a fairly simple library which allows you to &#8220;pair&#8221; the script with the TV and will then send cookie-authenticated requests to the TVs own web API to control pretty much everything. You can:
Set up the initial pairing between the script and the TV
Retrieve system information from the TV (serial, model, mac addr etc)
Enumerate the available TV inputs (HDMI1,2,3,4 etc)
Switch to a given input
Enumerate the remote control buttons
Virtually press those buttons
Find out what Smart TV apps are available
Start those apps
Enumerate the available DVB-T channels
Switch to those channels
Send Wake On Lan packets to switch the TV on from cold (assuming you&#8217;ve enabled that)
A couple of convenience functions
The library tries to hide the complexity and pre-requisites and give you an easy to use API.
I built this for a couple of reasons: 1. Because the TV had an undocumented API, and that tickles me 2. I quite fancied hooking it up to Alexa for lols
Most of the information about how to talk to the TV&#8217;s API came from looking at packet captures from the iPhone app &#8220;TV Sideview&#8221;.
There is a script called testit.py that will give you a few clues about how to use it, but it&#8217;s a bit of a mess. I&#8217;ve left a lot of comments in the code for the library which should help you.
Really, I think that this library should be imported in to a long-running process rather than be called every time you want to press a remote control button. On a Raspberry Pi, Requests can take a while (a couple of seconds) to import, and then bravialib pre-populates a few data sources, and all of that takes time, like about 20 seconds &#8211; so you really don&#8217;t want to use this library if you just want to fire a few remote control commands. Also &#8211; be aware that the TV takes a long time to boot and accept commands. From cold you&#8217;re talking about a minute maybe two, it&#8217;s really annoying.
The aforementioned long running process &#8211; bravia_rest.py
As the main library takes a while to start and needs a certain amount of data from the TV to work properly it really makes sense to start it up once and then leave it running as long as you can. The bravia_rest.py script does exactly that, and also exposes some of the functionality as a very crude REST interface that you can easily hook it in to various home automation systems.
First you need to add the IP address and MAC address (needed to turn on the TV the first time the script is run, it can be discovered automatically if you just power the TV on for a few minutes before you run the script).
Then run bravia_rest.py.
If this is the first time you have run it you will need to pair with the TV. You will be told to point your browser at the IP address of the machine where the script is running on port 8090 (by default). Doing this will make the script attempt to pair with the TV. If it works you will see a PIN number on the TV screen, you will need to enter this in to the box in your browser. After a few seconds, and with a bit of luck, pairing will now complete. This shouldn&#8217;t take too long.
If you are now paired, in your browser go to /dumpinfo for a view in to what the script knows about the TV.
Once everything is running you can POST to these URLs for things to happen (no body is required):
/set/power/[on|off] &#8211; turns the telly on and off
/set/send/&button& &#8211; e.g. mute, play, pause, up, down. See dumpinfo for all the key names.
/set/volumeup/3 &#8211; turn the volume up 3 notches. You MUST pass a number, even it it&#8217;s just 1.
/set/volumedown/1 &#8211; as above.
/set/loadapp/&app name& &#8211; e.g. Netflix, iplayer. Again /dumpinfo will show you what apps are available.
/set/channel/&channel& &#8211; e.g. BBC ONE, BBC TWO
/set/input/&input label& &#8211; You need to have given your inputs labels on the TV, then pass the label here.
Hooking it up to Alexa
Now we can poke the TV through a simplified REST interface, it&#8217;s much easier to hook in to other things, like Alexa for example. Setting up a custom skill in AWS/Lambda is beyond the scope of what I can write up at lunchtime, I&#8217;m sure there are lots of other people who have done it better than I could. You&#8217;ll need to create a custom app and upload a Python Deployment Package to Lambda including my lambda_function.py script (see inside the Alexa directory), a secrets.py file with your info in it, a copy of the Requests library (you need to create a Python Virtual Environment &#8211; it&#8217;s quite easy) and possibly a copy of your PEM for a self signed HTTPS certificate. I&#8217;ve also included the skills data such as the utterances that I&#8217;m using. These will need to be adjusted for your locale.
You can read more about Python deployment packages and AWS here:
Here&#8217;s how it works:
You issue the command to Alexa: Alexa tell The TV to change to channel BBC ONE.
Your voice is sent to AWS (the green lines) decoded and the utterances and intents etc are sent to the Lambda script.
The Lambda script works out what the requested actions are and sends them back out (the orange lines) to a web server running in your home (in my case a Raspberry Pi running Apache and the bravia_proxy.py script). You need to make that Apache server accessible to the outside world so that AWS can POST data to it. I would recommend that you configure Apache to use SSL and you put at least BASIC Auth in front of the proxy script.
The bravia_proxy.py script receives the POSTed form from AWS and in turn POSTs to the bravia_rest.py script having done a quick bit of sanity checking and normalisation. The proxy and the rest scripts could live on different hosts (and probably should, there are no security considerations in either script &#8211; so ya know, don&#8217;t use them.)
bravia_rest.py uses bravialib to poke the TV in the right way and returns back a yes or a no which then flows back (the blue lines) to AWS and your Lambda function.
If everything worked you should hear &#8220;OK&#8221; from Alexa and your TV should do what you told it.
I could have put bravia_rest.py straight on the web an implemented some basic auth and SSL there &#8211; but I think this is something better handled by Apache (or whichever server you prefer), not some hacked up script that I wrote.
It doesn&#8217;t deal with the TV being off at all well at the moment.
I don&#8217;t know what happens when the cookies expire.
I haven&#8217;t done much testing.
I have no idea what I&#8217;m doing.
As a analytically minded person, is it worth getting Amazon Prime?
I signed up yesterday and spent the evening setting up the various services.
It was on offer with ?20 off, it was the day before The Grand Tour came out, and I recently bought an Amazon Dot &#8211; well played Amazon, well played.
As I&#8217;m sure you&#8217;re aware Amazon Prime comes with a few bundled goodies to sweeten the deal. But are they actually useful? I think the real value is the next day delivery (if you order lots of things from Amazon), the online photo storage and perhaps the video. Everything else falls short of being good enough to be considered a real product in it&#8217;s own right.
Yes, I know that&#8217;s on purpose &#8211; but the marketing material would have you believe otherwise.
How about that.
The loan of a book a month from the Kindle Lending Library
Rating: 4/10 (based on going to an actual library being 8/10)
You&#8217;re not going to find many books you actually want to read in there. Browsing the catalogue from your desktop is virtually impossible and it&#8217;s been made that way deliberately. This is frustrating and annoying. Also annoying is that if you use the Kindle app on your phone you get nagged to upgrade to Kindle Unlimited all the bloody time.
You can share this with someone else on your household account, but they won&#8217;t thank you for it.
Prime Music
Rating: 6.5/10 (based on Spotify Premium being 10/10)
Better than I expected, but still full of annoyances. And again with the constant nagging to upgrade to Music Unlimited.
The selection is ok. It feels like they&#8217;ve taken the time to make it just-good-enough that you will use it but not good enough that you won&#8217;t consider upgrading.
You can&#8217;t share this perk with anyone else in your household, and since there&#8217;s no point in two people in your household having a Prime account each, you end up setting up another Chrome profile just to access the music service for managing play lists etc. Also annoying is that you can&#8217;t play music on an Echo or Dot and play music in the browser at the same time. This raises the question of what will happen if you have two Amazon Alexa devices on the same account and you try and play music on both. If you can&#8217;t (and I don&#8217;t know yet, perhaps someone can comment if they do) then one of the good features of Alexa is somewhat spoiled.
(Edit: some searching suggests that indeed you cannot listen to Prime Music on more than one device at at time.)
This service is a very good replacement for the kitchen radio but not a replacement for even a free Spotify subscription.
If you already have a premium Spotify account then this will be of no interest to you at all.
Prime Video
Rating: 7.5/10 (based on Netflix being 10/10)
Not so many nag screens here, but guess what, you still need to spend more money for the full experience.
It&#8217;s a bit galling to discover that some of the headline shows need to be paid for (Game Of Thrones for example).
But, there is some genuinely good exclusive content here, The Grand Tour for example.
I don&#8217;t see myself watching it more than Netflix but it&#8217;s worth, say, 3 quid a month of the ?6.50 a month Prime subscription.
Installing on an iPhone was easy enough, but on Android it&#8217;s outrageously bad.
You have to install Amazon&#8217;s &#8220;Underground&#8221; app store, and to do that you have to enable &#8220;Unknown Sources&#8221;.
The app works fine, and you can uninstall Underground once it&#8217;s on there.
The app on my Sony TV is fine.
Prime Video doesn&#8217;t support Chromecast, which isn&#8217;t a surprise but is, you guessed it, annoying.
Next Day Delivery
Rating: 10/10 (based on going to the shops being 1/10)
I don&#8217;t order that much from Amazon, which is why I&#8217;m wondering if this is all worth it, but when I do having it turn up the next day for &#8220;free&#8221; is nice.
Unlimited Online Photo Storage
Rating: 9/10 (based on Google Drive being 7/10)
Google also offer unlimited photo storage, but critically they compress your photos.
The Amazon offering does not (based on MD5 sums for a picture selected at random).
There is also an excellent Linux cli util called acd_cli ().
You&#8217;ll want to exclude videos and other files from being uploaded because they will count towards your 5GB limit for other stuff.
Something like this:
acd_cli --verbose ul -xe mov -xe mp4 -xe ini . /Pictures
Don&#8217;t be surprised if this has a storage limit applied in the future.
Prime Early Access
Rating: 0/10 (based on normal Amazon shopping being 10/10)
Early access to the electronic jumble sale that is Black Friday.
Pointless.
Twitch Prime
Rating: 5/10 (based on not having it being 0/10)
Skip this if you don&#8217;t know what Twitch is.
With Prime you can subscribe to a channel for a month for free.
It&#8217;s a free way to support Twitch streamers you like, and you get some crappy game add-ons that you won&#8217;t ever use.
Amazon Prime is basically shareware from the late 90s.
It does do what they claim, but there are constant nags to spend money on the basis that all the good stuff is just out of reach.
The new Amazon Dot in the kitchen was not warmly welcomed by everyone at Whizzy Towers but having it play music on demand has changed that perception quite a lot in the last day.
I have saved the first episode of The Grand Tour to watch tonight, which I am looking forward to since the reviews have been good, and all my photos which had previously been backed up on to a USB HDD are now slowly making their way to the cloud.
I also ordered a ?5 book yesterday which arrived today as promised.
However, the shortcomings have the feeling of being deliberate.
Which is more annoying than if the services were just a bit crap.
So all in all you&#8217;re getting what you pay for.
It&#8217;s not amazing value, but neither is it a total rip off.
Someone at Amazon has done their job well.
I would recommend you get it.
As you&#8217;re probably aware Ubuntu 16.10 was released yesterday and brings with it the Unity 8 desktop session as a preview of what&#8217;s being worked on right now and a reflection of the current state of play.
You might have already logged in and kicked the proverbial tyres.
If not I would urge you to do so.
Please take the time to install a couple of apps as laid out here:
The main driver for getting Unity 8 in to 16.10 was the chance to get it in the hands of users so we can get feedback and bug reports.
If you find something doesn&#8217;t work, please, log a bug.
We don&#8217;t monitor every forum or comments section on the web so the absolute best way to provide your feedback to people who can act on it is a bug report with clear steps on how to reproduce the issue (in the case of crashes) or an explanation of why you think a particular behaviour is wrong.
This is how you get things changed or fixed.
You can contribute to Ubuntu by simply playing with it.
Read about logging bugs in Ubuntu here:
And when you are ready to log a bug, log it against Unity 8 here:
There is no such thing as a &#8220;none&#8221; directive in Apache 2.
If you&#8217;ve got &#8220;deny from none&#8221; or &#8220;allow from none&#8221; then you&#8217;re doing DNS lookups on each host that connects regardless of whether you want to or not.
I was experiencing a very annoying problem trying to serve static HTML pages and CGI scripts from Apache 2 recently.
The problem manifested itself like this:
Running the scripts on the server hosting Apache shows they ran in well under a second
Connecting to the Apache server from the LAN, everything was fine and ran in under a second
Connecting to the Apache server from the Internet, but from a machine known to my network, ran fine
Connecting from an AWS Lambda script, suddenly there is a 20 second or more delay before getting data back
Connecting from Digital Ocean, there is a 20 second delay
Connecting from another computer on the internet, there is a 20 second delay
What the heck is going on here?
I spent time trying to debug my CGI scripts and adding lots more logging and finally convinced myself that it was a problem with the Apache config and not something like MTUs or routing problems.
But what was causing it?
It started to feel like like a DNS related issue since the machines where it ran fine where all known to me, and so had corresponding entries in my local DNS server.
But but but&#8230; I clearly had &#8220;HostnameLookups Off&#8221; in my apache2.conf file.
When I looked at the logs again, I noticed that indeed hostnames were being looked up, even though I told it not to.
Because I don&#8217;t know how to configure Apache servers properly.
At some point in time I thought this was a good idea:
Order deny, allow
Deny from none
Allow from all
But, there is no such thing as a &#8220;none&#8221; directive.
Apache interprets &#8220;none&#8221; as a host name and so has to look it up to see if it&#8217;s supposed to be blocking it or not, which causes a DNS lookup delays and hostnames to appear in your Apache logs.
Englightenment came from here:
There is also a suggestion that inline comments can do the same thing here:
Unity 7 has had a low graphics mode for a long time but recently we&#8217;ve been making it better.
has been making improvements to reduce the amount of visual effects that are seen while running in low graphics mode.
At a high level this includes things like:
Reducing the amount of animation in elements such as the window switcher, launcher and menus (in some cases down to zero)
Removing blur and fade in/out
Reducing shadows
The result of these changes will be beneficial to people running Ubuntu in a virtual machine (where hardware 3D acceleration is not available) and for remote-control of desktops with VNC, RDP etc.
Low graphics mode should enable itself when it detects certain GL features are not available (e.g. in a virtualised environment) but there are times when you might want to force it on.
Here&#8217;s how you can force low graphics mode on 16.04 LTS (Xenial) :
nano ~/.config/upstart/lowgfx.conf
Paste this into it:
start on starting unity7
pre-start script
initctl set-env -g UNITY_LOW_GFX_MODE=1
end script
Log out and back in
If you want to stop using low graphics comment out the initctl line by placing a &#8216;#&#8217; at the start of the line.
This hack won&#8217;t work in 16.10 Yakkety because we&#8217;re moving to systemd for the user session.
I&#8217;ll write up some instructions for 16.10 once it&#8217;s available.
Here&#8217;s a quick video of some of the effects in low graphics mode:
To remind myself as much as anything:
I run a dnsmasq server on my router (which is a ) to handle local DNS, DNS proxying and DHCP. For some reason one of the hosts stopped registering its hostname with the DHCP server, and so I couldn&#8217;t resolve its name to an IP address from other clients on my network.
I&#8217;m pretty sure it used to work, and I&#8217;m also pretty sure I didn&#8217;t change anything &#8211; so why did it suddenly stop? My theory is that the disk on the client became corrupt and a fsck fix removed some files.
Anyway, the cause is that the DHCP client didn&#8217;t know to send it&#8217;s hostname along with the DHCP request.
This is fixed by creating (or editing) /etc/dhcp/dhclient.conf and adding this line:
send host-name = gethostname();

我要回帖

更多关于 labelname 的文章

 

随机推荐