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…
  • Workshopshed
    Workshopshed over 10 years ago

    The solution here was to swap Python libraries from requests[security] to pycurl. Also rather than using Pip to install them, there's already a precompiled package to be applied using OPKG

     

    Enchanted Objects Design Challenge - Taming the Python

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • 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
  • Workshopshed
    Workshopshed over 10 years ago

    So there's two issues with installing OpenSSL, The first is that it needs PERL to configure it. That seems to be available over at http://downloads.openwrt.org/snapshots/trunk/ar71xx/generic/packages/packages/ the second issue is that it OPKG depends on it, so removing it will break OPKG until I've got it back on again...

     

    Having messed up that second point and re-installed my image, it would appear that Perl is also available on the main Arduino repository.

     

    Perl also needed a bunch of modules. There were modules that I could download but they did not include things needed by OpenSSL. So I downloaded the 5.10.1 version of perl from http://www.cpan.org/src/README.html and copied on on Exporter.pm, vars.pm,warnings.pm,  warnings\register.pm, strict.pm

     

    You can test this with

    perl -e 'use strict; print "ok"'

     

    I also reinstall Make

    opkg install make

     

    I then ran through the configure steps

    http://wiki.openssl.org/index.php/Compilation_and_Installation

     

    I had to re-add some of the execute x permissions to ./Config Utils/*.* and  as I'd unzipped on a Windows machine and the scripts had lost those.

     

    make depend

     

    ran successfully

     

    make all

     

    ran successfully

     

    make install

     

    Seems to have copied on the .so files but it's reported the following error....

     

    gcc -I.. -I../include  -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -Wa,--noexecstack -O3 -fomit-frame-pointer -Wall   -c -o md2test.o md2test.c
    md2test.c:1:10: error: expected '=', ',', ';', 'asm' or '__attribute__' before '.' token
    dummytest.c
              ^

     

    Need to review make all and see if we can build without tests, demos etc.

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

    Ok, so the above manual patching of the libffi source seems to have allowed me to build libffi and install it.

    However it's installed to /usr/local/ rather than /usr/ I've no idea what that means but I moved them over to the same folders as the others.

     

    The /usr Versus /usr/local Debate

     

    I've re-read the manual and you can fix that with an option on configure.

    You may want to tell configure where to install the libffi library and

    header files. To do that, use the --prefix configure switch.  Libffi

    will install under /usr/local by default.

     

    Also this whole build process did not copy on the headers so I've copied those in from /mnt/sda1/libffi-3.0.13/mips-unknown-linux-gnu/include to /usr/include/libffi

     

    The error of the day is now....

     

    creating build/temp.linux-mips-2.7/src/cryptography/hazmat/bindings/__pycache__
        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 -I/usr/include/python2.7 -c src/cryptography/hazmat/bindings/__pycache__/_Cryptography_cffi_f3e4673fx399b1113.c -o build/temp.linux-mips-2.7/src/cryptography/hazmat/bindings/__pycache__/_Cryptography_cffi_f3e4673fx399b1113.o
        src/cryptography/hazmat/bindings/__pycache__/_Cryptography_cffi_f3e4673fx399b1113.c:216:25: fatal error: openssl/aes.h: No such file or directory
         #include <openssl/aes.h>

     

    "To fix this problem, you have to install OpenSSL development package, which is available in standard repositories of all modern Linux distributions."


    Except for Arduino...

     

    So I'm guessing I need to repeat my steps with ffi but with openssl...

     

    https://www.openssl.org/source/

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

    There's a couple of references to this issue

     

    https://ghc.haskell.org/trac/ghc/ticket/9513?cversion=0&cnum_hist=3

    http://lists.gnu.org/archive/html/discuss-gnustep/2010-01/msg00035.html

     

    I tried copying the install-sh into my mips-unknown-linum-gnu folder and that does seem to have moved me onto a different error ldconfig: not found which I'm guessing as a missing dependency. I've logged an error on github for this

    https://github.com/atgreen/libffi/issues/189

     

    root@EnchantedCottage:/mnt/sda1/libffi-3.0.13# opkg install ldconfig
    Installing ldconfig (0.9.33.2-1) to root...
    Downloading http://downloads.openwrt.org/barrier_breaker/14.07/ar71xx/generic/packages/base/ldconfig_0.9.33.2-1_ar71xx.ipk.
    Configuring ldconfig.

     

    This time it does seem to have installed libffi but there's one line "ldconfig: /usr/local/lib/libffi.so.6 is not a symlink" which might still be an error

     

    root@EnchantedCottage:/mnt/sda1/libffi-3.0.13# make install
    MAKE mips-unknown-linux-gnu : 0 * install
    make[1]: Entering directory `/mnt/sda1/libffi-3.0.13/mips-unknown-linux-gnu'
    Making install in include
    make[2]: Entering directory `/mnt/sda1/libffi-3.0.13/mips-unknown-linux-gnu/include'
    make[3]: Entering directory `/mnt/sda1/libffi-3.0.13/mips-unknown-linux-gnu/include'
    make[3]: Nothing to be done for `install-exec-am'.
    ../../install-sh -c -d '/usr/local/lib/libffi-3.0.13/include'
    ../install-sh -c -m 644 ffi.h ffitarget.h '/usr/local/lib/libffi-3.0.13/include'
    make[3]: Leaving directory `/mnt/sda1/libffi-3.0.13/mips-unknown-linux-gnu/include'
    make[2]: Leaving directory `/mnt/sda1/libffi-3.0.13/mips-unknown-linux-gnu/include'
    Making install in testsuite
    make[2]: Entering directory `/mnt/sda1/libffi-3.0.13/mips-unknown-linux-gnu/testsuite'
    make[3]: Entering directory `/mnt/sda1/libffi-3.0.13/mips-unknown-linux-gnu/testsuite'
    make[3]: Nothing to be done for `install-exec-am'.
    make[3]: Nothing to be done for `install-data-am'.
    make[3]: Leaving directory `/mnt/sda1/libffi-3.0.13/mips-unknown-linux-gnu/testsuite'
    make[2]: Leaving directory `/mnt/sda1/libffi-3.0.13/mips-unknown-linux-gnu/testsuite'
    Making install in man
    make[2]: Entering directory `/mnt/sda1/libffi-3.0.13/mips-unknown-linux-gnu/man'
    make[3]: Entering directory `/mnt/sda1/libffi-3.0.13/mips-unknown-linux-gnu/man'
    make[3]: Nothing to be done for `install-exec-am'.
    ../../install-sh -c -d '/usr/local/share/man/man3'
    ../install-sh -c -m 644 ../../man/ffi.3 ../../man/ffi_call.3 ../../man/ffi_prep_cif.3 ../../man/ffi_prep_cif_var.3 '/usr/local/share/man/man3'
    make[3]: Leaving directory `/mnt/sda1/libffi-3.0.13/mips-unknown-linux-gnu/man'
    make[2]: Leaving directory `/mnt/sda1/libffi-3.0.13/mips-unknown-linux-gnu/man'
    make[2]: Entering directory `/mnt/sda1/libffi-3.0.13/mips-unknown-linux-gnu'
    make[3]: Entering directory `/mnt/sda1/libffi-3.0.13/mips-unknown-linux-gnu'
    ../install-sh -c -d '/usr/local/lib'
    /bin/ash ./libtool   --mode=install ../install-sh -c   libffi.la '/usr/local/lib'
    libtool: install: ../install-sh -c .libs/libffi.so.6.0.1 /usr/local/lib/libffi.so.6.0.1
    libtool: install: (cd /usr/local/lib && { cp -pR -f libffi.so.6.0.1 libffi.so.6 || { rm -f libffi.so.6 && cp -pR libffi.so.6.0.1 libffi.so.6; }; })
    libtool: install: (cd /usr/local/lib && { cp -pR -f libffi.so.6.0.1 libffi.so || { rm -f libffi.so && cp -pR libffi.so.6.0.1 libffi.so; }; })
    libtool: install: ../install-sh -c .libs/libffi.lai /usr/local/lib/libffi.la
    libtool: install: ../install-sh -c .libs/libffi.a /usr/local/lib/libffi.a
    libtool: install: chmod 644 /usr/local/lib/libffi.a
    libtool: install: ranlib /usr/local/lib/libffi.a
    libtool: finish: PATH="/bin:/sbin:/usr/bin:/usr/sbin:/sbin" ldconfig -n /usr/local/lib
    ldconfig: /usr/local/lib/libffi.so.6 is not a symlink
    ----------------------------------------------------------------------
    Libraries have been installed in:
       /usr/local/lib
    
    If you ever happen to want to link against installed libraries
    in a given directory, LIBDIR, you must either use libtool, and
    specify the full pathname of the library, or use the `-LLIBDIR'
    flag during linking and do at least one of the following:
       - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
         during execution
       - add LIBDIR to the `LD_RUN_PATH' environment variable
         during linking
       - use the `-Wl,-rpath -Wl,LIBDIR' linker flag
    
    See any operating system documentation about shared libraries for
    more information, such as the ld(1) and ld.so(8) manual pages.
    ----------------------------------------------------------------------
    ../install-sh -c -d '/usr/local/share/info'
    ../install-sh -c -m 644 ../doc/libffi.info '/usr/local/share/info'
    ../install-sh -c -d '/usr/local/lib/pkgconfig'
    ../install-sh -c -m 644 libffi.pc '/usr/local/lib/pkgconfig'
    make[3]: Leaving directory `/mnt/sda1/libffi-3.0.13/mips-unknown-linux-gnu'
    make[2]: Leaving directory `/mnt/sda1/libffi-3.0.13/mips-unknown-linux-gnu'
    make[1]: Leaving directory `/mnt/sda1/libffi-3.0.13/mips-unknown-linux-gnu'

    • 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 © 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