Searching for an easy way to install mraa on an Intel Edison

I’m trying to run a NodeJS project or a Python program to send temperature sensor data to a public URL.
I need to install mraa for that. But all I can find online is tutorials for compiling from source or cross-compiling mraa on the Intel Edison. Is there an easier way to have mraa installed? If not, how should I go about compiling mraa on an Intel Edison with balena OS installed on it?

Following the instructions at https://pypi.org/project/grove.py/ I get stuck at sudo apt install python-mraa python-upm which generates the errors:

E: Unable to locate package python-mraa
E: Unable to locate package python-upm

Hi,

The instructions mentioned adding package repository and the gpg key for it, have you done those steps yet?

Sure. Those steps work flawlessly.

And you run sudo apt update after you add the package repo, and before you run the install command?

I have those steps too and they don’t give problems.

Here’s the dockerfile I’m pushing with balena:

# base-image for python on any machine using a template variable,
# see more about dockerfile templates here: https://www.balena.io/docs/learn/develop/dockerfile/
FROM balenalib/%%BALENA_MACHINE_NAME%%-python:3-stretch-run

# use `install_packages` if you need to install dependencies,
# for instance if you need git, just uncomment the line below.

RUN apt-get update

RUN apt-get install apt-transport-https ca-certificates

RUN echo "deb https://seeed-studio.github.io/pi_repo/ stretch main" | sudo tee /etc/apt/sources.list.d/seeed.list

RUN curl https://seeed-studio.github.io/pi_repo/public.key | sudo apt-key add -

RUN sudo apt install software-properties-common

RUN sudo apt update

RUN sudo apt install python-mraa python-upm

RUN sudo apt update

RUN sudo apt install python-rpi.gpio python3-rpi.gpio

RUN sudo pip install rpi_ws281x

RUN sudo pip install grove.py

# Set our working directory
WORKDIR /usr/src/app

# Copy requirements.txt first for better cache on later pushes
# COPY requirements.txt requirements.txt

# pip install python deps from requirements.txt on the resin.io build server
# RUN pip install -r requirements.txt

# This will copy all files in our root to the working  directory in the container
COPY . ./

# Enable udevd so that plugged dynamic hardware devices show up in our container.
ENV UDEV=1

# main.py will run when container starts up on the device
CMD ["python","-u","temperature.py"]

Hi

Can you try reducing the number of run commands? So instead of

RUN curl https://seeed-studio.github.io/pi_repo/public.key | sudo apt-key add -

RUN sudo apt install software-properties-common

RUN sudo apt update

RUN sudo apt install python-mraa_1.9.0 python-upm_1.6.0

can you replace it with -

RUN curl https://seeed-studio.github.io/pi_repo/public.key | sudo apt-key add -; sudo apt update; sudo apt install software-properties-common; sudo apt install python-mraa_1.9.0 python-upm_1.6.0

I changed the dockerfile accordingly but the error persists.

Hi,

The package you install is only available for armhf/arm64 while your device is i386 (Intel Edison) so that’s why you hit the error.

I can find and install the package without any problems on armv7hf device.

root@f29e26010122:/# apt-cache policy python-mraa
python-mraa:
  Installed: 1.9.0-git20191021-pi20191021
  Candidate: 1.9.0-git20191021-pi20191021
  Version table:
 *** 1.9.0-git20191021-pi20191021 500
        500 https://seeed-studio.github.io/pi_repo stretch/main armhf Packages
        100 /var/lib/dpkg/status
1 Like

I was suspecting that. So, the only solution left is cross-compiling I guess.

Yes that makes sense.

1 Like

Ok. So…
It’s my first time cross-compiling.
Once I have the compiled library by following these steps where should I put the files on the Intel Edison running balena OS?

You will need to somehow incorporate the built artifacts into your Dockerfile. An option is to upload them somewhere and then download them from your Dockerfile. Another is to keep them in your project directory and copy them into your image during build.

Ok. And once I have the built library in my project directory, I should just run make install, right?

And what kind of toolchain will I need?

So ideally, you would use a multi-stage build approach for this. In your first build step, you would build the library/binary and in the second run step, you would just copy the assets across from the builder step (COPY --from=buildstep ...) to the correct runtime locations.

So your builder step may finish with RUN make install and then once you work out where the assets are copied, you’ll be able to craft the COPY --from... statement.

I’m running into some issues. I don’t know if I set up things correctly.

Here’s my Dockerfile:

# base-image for python on any machine using a template variable,
# see more about dockerfile templates here: https://www.balena.io/docs/learn/develop/dockerfile/
FROM balenalib/%%BALENA_MACHINE_NAME%%-python:3-stretch-run

# Set our working directory
# WORKDIR /usr/src/app
WORKDIR /home

RUN mkdir dusan; cd dusan; mkdir Scaricati

WORKDIR /home/dusan/Scaricati

# This will copy all files in our root to the working  directory in the container
COPY . ./

# use `install_packages` if you need to install dependencies,
# for instance if you need git, just uncomment the line below.

RUN sudo apt update

RUN apt install build-essential cmake

# Intel Poky Yocto toolchain
RUN sudo bash ./poky-edison-glibc-x86_64-edison-image-core2-32-toolchain-1.7.2.sh -y

RUN . /opt/poky-edison/1.7.2/environment-setup-core2-32-poky-linux

RUN cd mraa-1.5.0/build; sudo make install; cd ../..

RUN sudo apt update

RUN sudo apt install python-rpi.gpio python3-rpi.gpio

RUN sudo pip install rpi_ws281x

RUN sudo pip install grove.py

# Copy requirements.txt first for better cache on later pushes
# COPY requirements.txt requirements.txt

# pip install python deps from requirements.txt on the resin.io build server
# RUN pip install -r requirements.txt

# Enable udevd so that plugged dynamic hardware devices show up in our container.
ENV UDEV=1

# main.py will run when container starts up on the device
CMD ["python","-u","temperature.py"]

And here’s the error I’m getting:

[main]     Step 8/16 : RUN sudo bash ./poky-edison-glibc-x86_64-edison-image-core2-32-toolchain-1.7.2.sh -y
[main]      ---> Running in b56585b2ceb2
[main]     You are about to install the SDK to "/opt/poky-edison/1.7.2". Proceed[Y/n]?Y
[main]     Extracting SDK...
[Info]     Still Working...
[main]     done
[main]     Setting it up...
[main]     find: ‘file’: No such file or directory

Hey Dejan,
Going back to your original question and the Dockerfile you shared, I’m a bit confused by what you are trying to achieve. Can you clarify

  • your aim is to use the grove.py library but you are unable to install the libmraa libraries since you are using an intel Edison and the seeduino sources don’t provide a build for i386 architecture which the intel edison is. so you are subsequently trying to cross compile?

    • Given that the grove.py the rpi_ws281x libraries are targeted for the Raspberry Pi family, i’m not sure those would work on the edison anyway?

    Python library for Seeedstudio Grove Devices on Raspberry Pi.

  • a Python program to send temperature sensor data to a public URL

considering your original goal, I’m assuming you have a temperature sensor connected to the edison via the grove kit? I think you can try the following instead:

  • The mraa project provides instructions to install on ubuntu. there are precompiled packages for i386. so I suggest you use our ubuntu-python variant as the base image
  • You can then write the python code using the upm python library. that would depend on the interface of your temperature sensor.you might find pyupm_temperature module — upm v1.6.0-2-g20aa496 documentation useful

Also, here is the Dockerfile.template file to get you started with the ubuntu and precompiled libmraa/libupm

FROM balenalib/%%BALENA_MACHINE_NAME%%-ubuntu-python

RUN install_packages software-properties-common
RUN sudo add-apt-repository ppa:mraa/mraa && \
    apt-get update && \
    install_packages python3-mraa python3-upm

...
# add more steps here such as copying over temperature.py and running it 

Hope this is helpful.

Cheers,
Rahul

I managed to install mraa using the Dockerfile provided here.
But building upm fails at make:

[main]     [ 38%]
[main]     Building CXX object src/h3lis331dl/CMakeFiles/_pyupm_h3lis331dl.dir/h3lis331dl.cxx.o
[main]     /usr/src/upm-03e72e02f811cb9a47000a6f12fca61a2908d325/src/h3lis331dl/h3lis331dl.cxx: In constructor ‘upm::H3LIS331DL::H3LIS331DL(int, uint8_t)’:
[main]     /usr/src/upm-03e72e02f811cb9a47000a6f12fca61a2908d325/src/h3lis331dl/h3lis331dl.cxx:42:12: error: cannot convert ‘mraa::Result’ to ‘mraa_result_t’ in assignment
[main]        if ( (rv = m_i2c.address(m_addr)) != MRAA_SUCCESS)
[main]                 ^
[main]
[main]     make[2]: *** [src/h3lis331dl/CMakeFiles/_pyupm_h3lis331dl.dir/h3lis331dl.cxx.o] Error 1
[main]
[main]     src/h3lis331dl/CMakeFiles/_pyupm_h3lis331dl.dir/build.make:85: recipe for target 'src/h3lis331dl/CMakeFiles/_pyupm_h3lis331dl.dir/h3lis331dl.cxx.o' failed
[main]     CMakeFiles/Makefile2:3887: recipe for target 'src/h3lis331dl/CMakeFiles/_pyupm_h3lis331dl.dir/all' failed
[main]     make[1]: *** [src/h3lis331dl/CMakeFiles/_pyupm_h3lis331dl.dir/all] Error 2
[main]
[main]     make: *** [all] Error 2
[main]
[main]     Makefile:117: recipe for target 'all' failed
[main]     Removing intermediate container 39606d3c0056

I think I have to install from the latest commit.