element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Enchanted Objects
  • Challenges & Projects
  • Design Challenges
  • Enchanted Objects
  • More
  • Cancel
Enchanted Objects
Blog Enchanted Objects Design Challenge - The snake, the troll and the fighting dwarves
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Events
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: Workshopshed
  • Date Created: 19 Apr 2015 11:17 PM Date Created
  • Views 2111 views
  • Likes 5 likes
  • Comments 16 comments
  • enchanted_cottage
  • enchanted_objects
Related
Recommended

Enchanted Objects Design Challenge - The snake, the troll and the fighting dwarves

Workshopshed
Workshopshed
19 Apr 2015

After their successes with the mechanics and Arduino Yun, Hans and Matilda decided to celebrate with a trip to the local inn, the "Adam and Eve". They walked up to the bar and was greeted by the bartender. Whilst they were being served they noticed a large snake behind the bar.

Photos thanks to Will Russell

imageimage

Suddenly the door burst open and a large troll charged in and marched up to the bar. He started shouting in a language which Hans and Matilda did not recognise. The snake lifted it's head and proceeded to slide along the back of the bar until it reached a dusty looking bottle. The snake flicked its tongue. The bartender picked up the bottle and poured a generous measure into a glass and passed it to the troll. The troll slapped some gold coins on the bar and marched over to a full table of people who quickly vacated to give the troll a seat.

 

From over the other side of the bar Hans and Matilda heard some raised voices. A group of dwarves were having some drinks with a tall dark haired lady. A dwarf with glasses seemed to be angry with one of the others who he claimed was not doing his fair share of the mining. The argument quickly deteriorated into a fight and the accused dwarf picked up a bottle and raised it above his head. Before he could bring down his arm it was wrapped in the coils of the snake. Hans and Matilda watched in amazement as the two fighting dwarves disappeared into endless coils of snake. It was at this point they realised exactly how big the snake was. The snake and dwarf coils headed outside, shortly after only the snake returned.

 

After finishing their drinks, Hans and Matilda thanked the bartender and asked about the snake. He told them he had bought it from a Burmese traveller when it was only a foot long. He had initially fed it on rats caught in the cellar, now he just leaves it to roam the forest at night. Hans and Matilda walked home much more quickly than usual that evening.

 

The next morning Hans was working on the Arduino Yun, he realised that both the parsing of the weather data and also security checks could be handled in Python on the OpenWRT side of the Yun.

 

Hans thought that the Python script could return a simple string representing the weather, either success or an error with precipitation and temperature as additional parameters.

 

Message formats:
OK!,Cloudy,4,12.5
ERR,Timeout,0,0.0

 

He also confirmed that python already installed on the Yun.

image

Hans looked at the different options for reading an API and the requests library looks to be a good solution. It was straight forward to install this on the development machine.

 

pip install requests

 

To install it onto the Yun required a little more effort as PIP is not installed.

 

opkg update
opkg install distribute
opkg install python-openssl
easy_install pip

When Hans tried to install this, the Yun ran out of space. "No space left on device". So he followed the instructions for mounting the file system onto an SD card. http://www.arduino.cc/en/Tutorial/ExpandingYunDiskSpace. After making space for the tools used to expand the disks he succeeded expanding the disks and returned to installing pip.

 

To prove his concept would work he created a simple demo.

import requests, json
print 'Getting Weather'
weather_url = "https://query.yahooapis.com/v1/public/yql?q=select%20item.condition.text%20from%20weather.forecast%20where%20woeid%20in%20(select%20woeid%20from%20geo.places(1)%20where%20text%3D%22Chicago%20IL%22)&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys"
r = requests.get(weather_url)
print r.status_code
j = json.loads(r.content)
print j['query']['results']['channel']['item']['condition']['text']

 

Not a perfect result but definitely a few steps in the right direction.

root@EnchantedCottage:/mnt/sda1/Python# python GetWeather.py
Getting Weather
/usr/lib/python2.7/site-packages/requests/packages/urllib3/util/ssl_.py:79: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
200
Rain
root@EnchantedCottage:/mnt/sda1/Python#

 

Now it was just a case of dealing with the InsecurePlatformWarning, handling timeouts and network errors, parsing the JSON and passing in the correct location code.

 

Python Reference

Exception handling
http://doughellmann.com/2009/06/19/python-exception-handling-techniques.html

Make call using requests.get
http://isbullsh.it/2012/06/Rest-api-in-python/

Certificates
https://www.python.org/dev/peps/pep-0476/#trust-database

https://pypi.python.org/pypi/backports.ssl_match_hostname/

http://stackoverflow.com/questions/1087227/validate-ssl-certificates-with-python

Also timeouts etc here
http://docs.python-requests.org/en/latest/user/advanced/

 

Next: Enchanted Objects Design Challenge - The flaming postman, the blind man and a trip to the market

  • Sign in to reply

Top Comments

  • fvan
    fvan over 10 years ago +3
    It's been said by others before, but I really like the way you bring your story
  • mcb1
    mcb1 over 10 years ago in reply to fvan +3
    It was a long path to make the snake/python connection ... but clever. Well done Andy ...just don't start writing childrens books. Mark
  • Workshopshed
    Workshopshed over 10 years ago +1
    I tried installing the security fixes with pip install requests[security] that gave me errors about not having a gcc so I've installed that too. Then I got a new error about not having the Python.h file…
Parents
  • Workshopshed
    Workshopshed over 10 years ago

    Uurgh, managed to get OpenSSL to compile but now seem to have lost the ability to create a libffi shared library. Was previously using the linino image but when reflashed to fix problem with OpenSSL, I reverted to the standard Arduino image..

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
Comment
  • Workshopshed
    Workshopshed over 10 years ago

    Uurgh, managed to get OpenSSL to compile but now seem to have lost the ability to create a libffi shared library. Was previously using the linino image but when reflashed to fix problem with OpenSSL, I reverted to the standard Arduino image..

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube