This week, we publish a new version of all of our libraries and of the VirtualHub. Among the improvements, the Android, C++, C#, Delphi, Java, JavaScript, Objective-C, PHP, and VB.Net libraries are now also available on GitHub. Likewise, you can download the Python library easily via PyPI (Python Package Index). To illustrate these changes, we are going to update our "PiCooker" example software so that it uses the library available on PyPI. We will take this opportunity to make a few improvements to the code.
Before explaining the new methods to install the programming libraries, here is the list of improvements brought to the VirtualHub and to the libraries.
VirtualHub:
- Improve user interface of HTTP CallBack setup window
- Improve handling of connection timeout
- Improve user interface for mobile and touch-based browsers
- Improve handling of device disconnection in the middle of a request close
- Fix race condition causing truncated requests in some cases (in particular for Windows)
- Fix possible crash when disconnecting a black-listed device on Mac OS X
- Fix segmentation fault after a Ctrl-C on Linux system with ARM processor
- Fix possible crash on device disconnect
Programming libraries:
- Fix possible crash when disconnecting a black-listed device on Mac OS X
- Fix segmentation fault during FreeAPI() on Linux system with ARM processor
- Improve handling of device disconnection in the middle of a request close
- Add ANT build script for Android library
- Use applicationContext instead of ActivityContext for BroadCastReceivers for Android
- Fix module() method for Java and Android Library
- Minor fixes
GitHub
As several customers asked us for it, we have decided to publish from now on our libraries simultaneously on GitHub and on our web site. The library sources, the examples, the documentation and the Makefile are included. However, unlike of the archives on our web site, the GitHub version does not contain compiled binaries of the examples.
If you use Git, it makes it easier for you to integrate Yoctopuce libraries into your projects. No need anymore to unzip the archive and to manually add files in your Git repository. At the next update, you will only need to update your local repository and to recompile your project to update your application. Proposing us a fix or an improvement for our libraries will also be easier.
As all our libraries have a license allowing you a very large use of them (use, modification, copy, integration) with the single condition that you use them with our products, you can create your own Git branch and customize your library as you wish.
The libraries are available as of now on our GitHub account http://github.com/yoctopuce.
PyPI
We also decided to publish our Python library on PyPI (the Python Package Index) to simplify the life of Python developers. As with GitHub, the library contains the sources, the examples, and the documentation.
There is nevertheless a small difference in use with the PyPI library: you must prefix the includes with yoctopuce. For example, to use a temperature sensor and a relay, you must include the library like this:
from yoctopuce.yocto_api import *
from yoctopuce.yocto_temperature import *
from yoctopuce.yocto_relay import *
Raspberry Pi, PyPI, and Yoctopuce
To illustrate the use of the PyPI library, we visited again the PiCooker example which we described in this post. We took this opportunity to improve the software to enable it to use all the temperature sensors connected to the Raspberry Pi (and not only one like until now).
Before starting to install our library, make sure your Raspberry Pi is up-to-date by running "sudo raspi-config" and by selecting "update". Unfortunately, the Raspberry Pi USB bug is still not completely fixed. You must therefore make sure that your /boot/cmdline.txt file contains the dwc_otg.speed=1 option. When these two operations are performed, reboot your Raspberry Pi and you are ready to install the Python library. Edit: The "dwc_otg.speed" option is no more needed on Raspberry Pi B+ and later models.
If you have never installed a library from PyPI, you must install the pip tool enabling you to download and install a PyPI package. If you have used pip previously on your Raspberry Pi, you can skip this step which is described in the following paragraph.
To install pip , you need the setuptools package. Install it with the sudo apt-get install python-setuptools command. Then, to install pip itself, there are several methods which are described on this page. On the Raspberry, the simplest way is to use the get-pip script which is available on GitHub.
curl -O https://raw.github.com/pypa/pip/master/contrib/get-pip.py sudo python get-pip.py
When pip is installed, simply run the pip install command to install a PyPI package. To install the Yoctopuce library, you must therefore run:
pip install yoctopuce
Easy, right? pip automatically downloads and installs the most recent library on your machine in the correct directory. To check that the installation went well, you can launch a Python interpreter and run the following lines:
Python 2.7.3 (default, Jan 13 2013, 11:20:46)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from yoctopuce.yocto_api import *
>>> print(YAPI.GetAPIVersion())
1.01.11167 (1.01.11167)
>>>
With the next version of the library, you only need to add the -U option to update your installation.
pip install -U yoctopuce
The PiCooker V1.2
If we run the original PiCooker script, Python stops with the following error: ImportError: No module named yocto_api.
As we wrote above, if you want to use the PyPI library, you must prefix the include with yoctopuce. You must therefore replace
from yocto_api import *
from yocto_temperature import *
by
from yoctopuce.yocto_api import *
from yoctopuce.yocto_temperature import *
We took this opportunity to improve the PiCooker, our small example which monitors cooking with a Raspberry Pi. You can download the new version on GitHub. We added the possibility to use several temperature sensors, connected to the same Raspberry Pi. As a reminder, the command line to run the PiCooker looks like this:
./picooker.py --smtp_host=smtp.gmail.com --smtp_port=465 --smtp_user=myemail@gmail.com --smtp_pass=mypassword
Naturally, your must adapt these parameters depending on your email and internet providers. The correct SMTP port can be 25, 465, or 587. In case of doubt, try them one after the other until you find the one that works. To make your life easier, this new version of the software sends a test email at start-up to check that the SMTP parameters are correct.