Comments (5)
Thanks for the quick feedback. I was trying payloads like { "set_pixel" : { "x": 0, "y": 0, "args": [255, 255, 255] } }
or { "set_pixel" : { "x": 0, "y": 0, "pixel": [255, 255, 255] } }
, but since *args is not named, they didn't work - just as you said. Due to the signature of set_pixel I guess we just can't mixed named and non-named vars.
I tried to do some magic with having a special "args" in kwargs, popping it and passing then both kwargs and args into set_pixel but it was not working, so just simply edited toe code to:
elif f=='set_pixel': sense_led.sense.set_pixel(*f_kwargs)
And then using the payload { "set_pixel" : [0, 0, 255, 255, 255] }
works fine.
from rpi-sensehat-mqtt.
none of them worked
can you provide an example of payload?
the portion of the code that is relevant to you is the following:
rpi-sensehat-mqtt/rpi_sensehat_mqtt.py
Lines 58 to 78 in 2b38005
in short, it assumes you are passing key
:value
(kwarg) structure when it mentions f_kwargs
, as in a dictionary data structure. so, a method, such as set_pixel()
must define named parameters for this to work. according to the code you mentioned, it does--namely, x
and y
. the problem is how pixels
is implemented there. it assumes that they are expanded by args
(e.g., tuple or list-like structure) that gives the RGB or an iterable that contains them, but such parameter is not named in the signature of the method, and therefore, the line
elif f=='set_pixel': sense_led.sense.set_pixel(**f_kwargs)
won't work. A simple fix is to edit it to parse as *args
instead (unnamed expansion) and in your payload, you send an iterable with the parameter values:
elif f=='set_pixel': sense_led.sense.set_pixel(*f_kwargs)
{
"set_pixel" : "[x,y,r,g,b]"
}
if that doesn't work, then you might need to do a bit of preprocessing on the payload. say, pass a string with a comma separating the parameters and then do the following:
elif f=='set_pixel': sense_led.sense.set_pixel(*f_kwargs.split(','))
{
"set_pixel" : "x,y,r,g,b"
}
that's my intuition right now. it's been a while since I last touched this code... anyway, give it a try, play around with it, and let me know if it doesn't work.
from rpi-sensehat-mqtt.
for my own future reference:
elif f=='set_pixel': sense_led.sense.set_pixel(*f_kwargs.split(','))
this actually might be a better strategy for sending and parsing payloads.
from rpi-sensehat-mqtt.
If I may ask for some more improvement, now I can send multiple commands, but only different commands. That is not that useful (flipping and setting a pixel?) - I guess most use cases are either just show a text/image, or setting 1 or more pixels. This latter is not possible at the moment, it needs separate mqtt messages. I don't mind, will handle it with node-red, but it's a suggestion.
Also, it would be awesome if this module would handle some timing transparently (like fading or blinking), which is difficult todo externally (what if some messages get lost, the case of clearing a blinking pixel means stopping a blinking cycle, etc.). But I know this is really just a wrapper for the sensehat library. :)
from rpi-sensehat-mqtt.
But I know this is really just a wrapper for the sensehat library
exactly. the enhancements you mentioned are sensible ones and there are other things I want to improve in the current implementation (one of the threads use way too much cpu time and I'm not sure why). however, my hands are full at the moment (and will likely continue to be until the end of the year).
if you don't mind, please open a new issue for each of such enhancement requests and I'll try to take a closer look at them when I have a bit of free time. also, feel free to make the changes yourself and submit a PR to add them here. help is always welcomed!
from rpi-sensehat-mqtt.
Related Issues (3)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rpi-sensehat-mqtt.