element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • 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 & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
    About the element14 Community
  • 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
      •  Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      •  Vietnam
      • 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 2601 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 11 years ago +3
    It's been said by others before, but I really like the way you bring your story
  • mcb1
    mcb1 over 11 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 11 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…
  • Workshopshed
    Workshopshed over 11 years ago in reply to Workshopshed

    Possible reference for the make install issue http://sourceware.org/ml/libffi-discuss/2012/msg00241.html

    All of the different package sources seem to have a libffi package prebuild although might need to rebuild the headers for this earlier version as there's no corresponding libffi-dev pacakge. Latest built version at Index of /barrier_breaker/14.07/ar71xx/generic/packages/packages/

    Also this seems relavent? https://lists.openwrt.org/pipermail/openwrt-devel/2014-October/028485.html

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

    Running configure for ffi gave me an error about grep which I'd seen when doing the attempt at Python2.7.9

     

    checking for grep that handles long lines and -e... configure: error: no acceptable grep could be found in /bin:/sbin:/usr/bin:/usr/sbin:/usr/xpg4/bin

     

    I found a fix for grep but then realised I'd not got "make", again I had see then when doing the Python build (which is when I was on the Linino distribution) so I got it from there.

     

    opkg update
    opkg install libpcre
    opkg upgrade grep
    wget http://download.linino.org/linino_distro/master/latest/packages/make_3.81-1_ar71xx.ipk
    opkg install make_3.81-1_ar71xx.ipk

     

    So that allowed me to continue with

     

    ./configure
    make

     

    Both which seemed to run without error.

     

    However "make install" reported a problem

    root@EnchantedCottage:/mnt/sda1/libffi-3.2.1# make install
    MAKE mips-unknown-linux-uclibc : 0 * install
    make[1]: Entering directory `/mnt/sda1/libffi-3.2.1/mips-unknown-linux-uclibc'
    Making install in include
    make[2]: Entering directory `/mnt/sda1/libffi-3.2.1/mips-unknown-linux-uclibc/include'
    make[3]: Entering directory `/mnt/sda1/libffi-3.2.1/mips-unknown-linux-uclibc/include'
    make[3]: Nothing to be done for `install-exec-am'.
     ../../install-sh -c -d '/usr/local/lib/libffi-3.2.1/include'
     ../install-sh -c -m 644 ffi.h ffitarget.h '/usr/local/lib/libffi-3.2.1/include'
    /bin/ash: ../install-sh: not found
    make[3]: *** [install-nodist_includesHEADERS] Error 127
    make[3]: Leaving directory `/mnt/sda1/libffi-3.2.1/mips-unknown-linux-uclibc/include'
    make[2]: *** [install-am] Error 2
    make[2]: Leaving directory `/mnt/sda1/libffi-3.2.1/mips-unknown-linux-uclibc/include'
    make[1]: *** [install-recursive] Error 1
    make[1]: Leaving directory `/mnt/sda1/libffi-3.2.1/mips-unknown-linux-uclibc'
    make: *** [install] Error 2

     

    I ran "make install" from the include directory and that fixed the /bin/ash: ../install-sh: not found error.

     

    make install
    make[1]: Entering directory `/mnt/sda1/libffi-3.2.1/mips-unknown-linux-uclibc/include'
    make[1]: Nothing to be done for `install-exec-am'.
     ../../install-sh -c -d '/usr/local/lib/libffi-3.2.1/include'
     ../../install-sh -c -m 644 ffi.h ffitarget.h '/usr/local/lib/libffi-3.2.1/include'
    make[1]: Leaving directory `/mnt/sda1/libffi-3.2.1/mips-unknown-linux-uclibc/include'

     

    The Pip install requests[security] still errored saying that it could not find the files so I copied the header files to /usr/include/libffi

     

    Now my error is:

     

      Running setup.py install for cffi
        Complete output from command /usr/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip-build-DTUFkL/cffi/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-GNE657-record/install-record.txt --single-version-externally-managed --compile:
        running install
        running build
        running build_py
        creating build
        creating build/lib.linux-mips-2.7
        creating build/lib.linux-mips-2.7/cffi
        copying cffi/commontypes.py -> build/lib.linux-mips-2.7/cffi
        copying cffi/__init__.py -> build/lib.linux-mips-2.7/cffi
        copying cffi/model.py -> build/lib.linux-mips-2.7/cffi
        copying cffi/vengine_gen.py -> build/lib.linux-mips-2.7/cffi
        copying cffi/lock.py -> build/lib.linux-mips-2.7/cffi
        copying cffi/vengine_cpy.py -> build/lib.linux-mips-2.7/cffi
        copying cffi/cparser.py -> build/lib.linux-mips-2.7/cffi
        copying cffi/ffiplatform.py -> build/lib.linux-mips-2.7/cffi
        copying cffi/api.py -> build/lib.linux-mips-2.7/cffi
        copying cffi/backend_ctypes.py -> build/lib.linux-mips-2.7/cffi
        copying cffi/verifier.py -> build/lib.linux-mips-2.7/cffi
        copying cffi/gc_weakref.py -> build/lib.linux-mips-2.7/cffi
        running build_ext
        building '_cffi_backend' extension
        creating build/temp.linux-mips-2.7
        creating build/temp.linux-mips-2.7/c
        mips-openwrt-linux-uclibc-gcc -fno-strict-aliasing -Os -pipe -mips32r2 -mtune=mips32r2 -fno-caller-saves -fhonour-copts -Wno-error=unused-but-set-variable -msoft-float -DNDEBUG -Os -pipe -mips32r2 -mtune=mips32r2 -fno-caller-saves -fhonour-copts -Wno-error=unused-but-set-variable -msoft-float -fPIC -DUSE__THREAD -I/usr/include/ffi -I/usr/include/libffi -I/usr/include/python2.7 -c c/_cffi_backend.c -o build/temp.linux-mips-2.7/c/_cffi_backend.o
        mips-openwrt-linux-uclibc-gcc -shared -L/home/jenkins/jenkins/jobs/yun-openwrt/workspace/staging_dir/target-mips_r2_uClibc-0.9.33.2/usr/lib -L/home/jenkins/jenkins/jobs/yun-openwrt/workspace/staging_dir/target-mips_r2_uClibc-0.9.33.2/lib -L/home/jenkins/jenkins/jobs/yun-openwrt/workspace/staging_dir/toolchain-mips_r2_gcc-4.6-linaro_uClibc-0.9.33.2/usr/lib -L/home/jenkins/jenkins/jobs/yun-openwrt/workspace/staging_dir/toolchain-mips_r2_gcc-4.6-linaro_uClibc-0.9.33.2/lib build/temp.linux-mips-2.7/c/_cffi_backend.o -lffi -o build/lib.linux-mips-2.7/_cffi_backend.so
        /usr/bin/ld: cannot find -lffi
        collect2: error: ld returned 1 exit status
        error: command 'mips-openwrt-linux-uclibc-gcc' failed with exit status 1
    
        ----------------------------------------
        Command "/usr/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip-build-DTUFkL/cffi/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-GNE657-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-DTUFkL/cffi

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

    After several hours of searching I gave up. As I'd spotted that option in the newer GCC headers I thought I'd try installing a newer GCC.

    I found one over at OpenWRT

     

    Ref: http://www.dd-wrt.com/phpBB2/viewtopic.php?p=919720
         http://noblepepper.com/wp/blog/2014/10/22/gcc-g-on-an-arduino-yun/

     

    I had to remove the old version and install the newer one. This is a bit of a risky process according to opkg as I had to remove an "essential" package to replace it with the newer one.

     

    opkg remove yun-gcc
    cd /mnt/sda1/
    wget http://downloads.openwrt.org/snapshots/trunk/ar71xx/generic/packages/packages/gcc_4.8.3-1_ar71xx.ipk
    wget http://downloads.openwrt.org/barrier_breaker/14.07/ar71xx/generic/packages/base/libstdcpp_4.8-linaro-1_ar71xx.ipk
    opkg --force-remove --force-removal-of-essential-packages remove libstdcpp
    opkg --force-remove remove gcc
    opkg install libstdcpp_4.8-linaro-1_ar71xx.ipk
    opkg install gcc_4.8.3-1_ar71xx.ipk

     

     

    Now the pip install requests[security] gave me an error about not finding Python.h. The Linux forums suggested I needed to install the Python-dev package. Something that does not seem to exist for the Yun. So I downloaded 2.7.3 Python and extracted files using tar -xz -f Python-2.7.3.tgz. Next I copied Python.h to /usr/include/python2.7

     

    That produced an other error about patchlevel.h so I copied the whole of the /include folder into /usr/include/python2.7.

     

    My latest error is "fatal error: ffi.h: No such file or directory", I've got the ffi source but there's no ffi.h header, I'm guessing that the configure script will build one of those. Let's hope I have more luck with that than the configure script for Python 2.7.9 which kept telling me that my int has size 0.

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

    Running "opkg install binutils" got rid of my "as" error. Now just have the -fhonour-copts issue, there's no mention of that option in the cffi package.

     

    Collecting cffi>=0.8 (from cryptography>=0.7->pyOpenSSL->requests[security])
      Using cached cffi-0.9.2.tar.gz
        Complete output from command python setup.py egg_info:
        cc1: error: unrecognized command line option '-fhonour-copts'
        cc1: error: unrecognized command line option '-fhonour-copts'
        cc1: error: unrecognized command line option '-fhonour-copts'
        cc1: error: unrecognized command line option '-fhonour-copts'
            No working compiler found, or bogus compiler options
            passed to the compiler from Python's distutils module.
            See the error messages above.
            (If they are about -mno-fused-madd and you are on OS/X 10.8,
            see http://stackoverflow.com/questions/22313407/ .)
        ----------------------------------------
        Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-dN9Psq/cffi

     

    I just can't work out where that option might be set.

     

    root@EnchantedCottage:/mnt/sda1/Python# gcc -v
    Using built-in specs.
    COLLECT_GCC=gcc
    COLLECT_LTO_WRAPPER=/usr/bin/../libexec/gcc/mips-openwrt-linux-uclibc/4.6.2/lto-wrapper
    Target: mips-openwrt-linux-uclibc
    Configured with: ../yun-gcc-4.6.2/configure --host=mips-openwrt-linux-uclibc --target=mips-openwrt-linux-uclibc --prefix=/home/jenkins/jenkins/jobs/yun-openwrt/workspace/staging_dir/target-mips_r2_uClibc-0.9.33.2/yun-gcc --disable-subdir-texinfo MAKEINFO=missing --disable-decimal-float --disable-libquadmath --disable-lto --enable-languages=c,c++
    Thread model: posix
    gcc version 4.6.2 (GCC)

     

    There also seems to be headers for both 4.6.2 and 4.6.3 but I can't see how you'd change that. The 4.6.3 headers do actually mention -fhonor-copts in options.h

     

    There's nothing in ENV either than mentions this.

     

    Can anyone give me a point in the right direction?

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

    Just realised "as" is the GNU assembler, that seems to be in the bintools package, I'll check if installing that removes the errors.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
<>
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 © 2026 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.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube