Mote pHAT API

I’m trying to convert the Mote API to work on the pHAT, but I’m having no luck. Are there any plans to release a version for the Mote pHAT as well?

Thanks!

We have a Mote pHAT specific library which you can find here: https://github.com/pimoroni/mote-phat

Hi, thanks for your reply.

I was thinking about an API something in line with https://github.com/pimoroni/mote/blob/master/python/examples/mote-api.py which I have been unable to use on the pHAT version.

Ooooh, the Mote API. Sorry, I forgot that existed. @sandyjmacdonald made an attempt to explain it to me, but I think I was having a brainfail yesterday.

You should be able to just find the line:

from mote import Mote

And replace it with:

import motephat as mote

Then delete:

mote = Mote()

Alright, perfect, I will try that when I get home :)

What does mote= Mote() do and why isn’t it needed?

that line creates an instance of the Mote class… the USB version of mote requires a bunch of setup for the client to function over serial, something the mote pHAT doesn’t require.

… Mote pHAT is more like a multiplexed ‘blinkt’ implementation IIRC, and crucially addresses gpio directly for communication.

Coincidentally, I had done exactly what Phil suggested to get it working with the MotePhat and it does work, but I’m seeing some strange behaviour. I’m not sure yet if this is some artefact of my configuration, poor soldering on my part, or some strange bug somewhere.

The problem is that when I call the /channel/all/state/on endpoint, only half the pixels on each mote stick turn on (pixels 1 to 8). If I then call the channel/all/colour endpoint, the other half of each mote stick (pixels 9 through 16) turn on with that colour.

I’ve double checked the behaviour on a freshly pre-started Pi with MotePhat, compared to a similarly restarted Pi with Mote Hub, which works as expected.

I will continue to investigate.

R

I got it to work as well, however I’m having the same isues as you do with the state/on, very strange.

I also haven’t figured out how to change the colors. It looks like it’s supposed to be in hex, but with #CC00FF I’m getting 404, and with CC00FF I’m getting the following error:

192.168.1.193 - - [14/Jan/2017 12:18:44] "GET /mote/channel/1/colour/CC00FF HTTP/1.1" 500 -
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/flask/app.py", line 1836, in __call__
    return self.wsgi_app(environ, start_response)
  File "/usr/lib/python3/dist-packages/flask/app.py", line 1820, in wsgi_app
    response = self.make_response(self.handle_exception(e))
  File "/usr/lib/python3/dist-packages/flask/app.py", line 1403, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/lib/python3/dist-packages/flask/_compat.py", line 33, in reraise
    raise value
  File "/usr/lib/python3/dist-packages/flask/app.py", line 1817, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/lib/python3/dist-packages/flask/app.py", line 1477, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/lib/python3/dist-packages/flask/app.py", line 1381, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/lib/python3/dist-packages/flask/_compat.py", line 33, in reraise
    raise value
  File "/usr/lib/python3/dist-packages/flask/app.py", line 1475, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/lib/python3/dist-packages/flask/app.py", line 1461, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/nbla/api.py", line 123, in set_colour
    status['colour'][int(channel)] = hex_to_rgb(c)
  File "/home/nbla/api.py", line 39, in hex_to_rgb
    return tuple(int(value[i:i + length / 3], 16) for i in range(0, length, length / 3))
TypeError: 'float' object cannot be interpreted as an integer

Ooops, didn’t read carefully enough…

{removed as irrelevant} Passing # is problematic, so the latter is correct.

Second edit - the URL looks wrong:
14/Jan/2017 12:18:44] “GET /mote/channel/1/colour/CC00FF HTTP/1.1”

Should be by default:
/mote/api/v1.0/channel/1/colour/CC00FF

Can you double check?
R

Sorry about that Raruston, had to change a bit in the beginning before I got it to work at all, but I reverted back to the original with the two changes gadgetoid suggested earlier in the thread.

However, I still got the same error…

Silly me, I usually run my tests with python3, tried it again now with python and it works, so case closed! :)

Thanks for all the help!

Still got the issue with half of the pixels changing state etc as you also have.