# Pixelblaze-client: Python 3 library for Pixelblaze

**URL:** <https://forum.electromage.com/t/pixelblaze-client-python-3-library-for-pixelblaze/756>\
**Category:** Patterns and Code\
**Created:** [November 24, 2020, 2:50am UTC](https://forum.electromage.com/t/pixelblaze-client-python-3-library-for-pixelblaze/756 "2020-11-24T02:50:20Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![wizard](https://forum.electromage.com/user_avatar/forum.electromage.com/wizard/32/4_2.png) [@wizard](https://forum.electromage.com/u/wizard)\
**Post date:** [December 1, 2020, 8:55pm UTC](https://forum.electromage.com/t/pixelblaze-client-python-3-library-for-pixelblaze/756/21 "2020-12-01T20:55:55Z")

</div>

@zranger1 you have my permission and support 🙂

BTW I think the naming thread was just for the the package name in PyPi (mentioned by @vutang50). But if you do want to [rename the repo, GitHub made it easy,](https://docs.github.com/en/free-pro-team@latest/github/administering-a-repository/renaming-a-repository#:~:text=On%20GitHub%2C%20navigate%20to%20the,Click%20Rename.) no re-create necessary.

---

<div class="post-metadata">

**Author:** ![zranger1](https://forum.electromage.com/user_avatar/forum.electromage.com/zranger1/32/301_2.png) [@zranger1](https://forum.electromage.com/u/zranger1)\
**Post date:** [December 1, 2020, 9:10pm UTC](https://forum.electromage.com/t/pixelblaze-client-python-3-library-for-pixelblaze/756/22 "2020-12-01T21:10:59Z")

</div>

Thanks @wizard!  
LOL, just habit from years in the world of extremely large software, where renaming or moving anything generates an instant flood of support traffic. What I’m doing is this:

- Create and test new repository, leaving the old one in place
- Once the new one is working, empty out the old one, leave just the readme with a pointer to the new repository, and an apology for Disturbing The Force by renaming and/or moving things.

---

<div class="post-metadata">

**Author:** ![zranger1](https://forum.electromage.com/user_avatar/forum.electromage.com/zranger1/32/301_2.png) [@zranger1](https://forum.electromage.com/u/zranger1)\
**Post date:** [December 1, 2020, 10:21pm UTC](https://forum.electromage.com/t/pixelblaze-client-python-3-library-for-pixelblaze/756/23 "2020-12-01T22:21:56Z")

</div>

[pixelblaze-client](https://github.com/zranger1/pixelblaze-client) is now up on github. I’ll work out the namespace and setup issues and see if I can get us published on PyPi in the next few days. It’ll (eventually) simpler for users.

---

<div class="post-metadata">

**Author:** ![spazzle](https://forum.electromage.com/user_avatar/forum.electromage.com/spazzle/32/2874_2.png) [@spazzle](https://forum.electromage.com/u/spazzle)\
**Post date:** [December 2, 2020, 1:23am UTC](https://forum.electromage.com/t/pixelblaze-client-python-3-library-for-pixelblaze/756/24 "2020-12-02T01:23:52Z")

</div>

I think some form of finding units on a network is still key. A likely use is setting up an installation somewhere and the units IPs will not be known.

---

<div class="post-metadata">

**Author:** ![zranger1](https://forum.electromage.com/user_avatar/forum.electromage.com/zranger1/32/301_2.png) [@zranger1](https://forum.electromage.com/u/zranger1)\
**Post date:** [December 2, 2020, 1:50am UTC](https://forum.electromage.com/t/pixelblaze-client-python-3-library-for-pixelblaze/756/25 "2020-12-02T01:50:45Z")

</div>

It’s coming… requires a little messing about with threading and a datagram listener. I’ll do detection and Firestorm style time synchronization (though probably not the pattern cloning) with this set of tools too. It’ll be a separate class for which I have not yet thought of a good name – PixelblazeDetector? ArmyofPixelblazes?

People in this part of the country come up with place names like “Big Balanced Rock”, and “Numerous Potholes”. The lack of imagination may have finally gotten to me.

---

<div class="post-metadata">

**Author:** ![spazzle](https://forum.electromage.com/user_avatar/forum.electromage.com/spazzle/32/2874_2.png) [@spazzle](https://forum.electromage.com/u/spazzle)\
**Post date:** [December 2, 2020, 2:04am UTC](https://forum.electromage.com/t/pixelblaze-client-python-3-library-for-pixelblaze/756/26 "2020-12-02T02:04:54Z")

</div>

Yeah, pattern cloning is not really needed.

---

<div class="post-metadata">

**Author:** ![vutang50](https://forum.electromage.com/letter_avatar_proxy/v4/letter/v/48db29/32.png) [@vutang50](https://forum.electromage.com/u/vutang50)\
**Post date:** [December 2, 2020, 6:05am UTC](https://forum.electromage.com/t/pixelblaze-client-python-3-library-for-pixelblaze/756/27 "2020-12-02T06:05:51Z")

</div>

Excellent! I appreciate the addition of `getColorControlName()` as that made the integration code much cleaner. This suits my needs as I don’t want to have to think about an arbitrary number of color pickers as I only want to focus on 1, but its incredible how flexible and dynamic the Pixelblaze UI and controls can be.

Next steps is to automate with HASS and Node-Red so that when my media players play a song, I can switch to a sound pattern.

---

<div class="post-metadata">

**Author:** ![zranger1](https://forum.electromage.com/user_avatar/forum.electromage.com/zranger1/32/301_2.png) [@zranger1](https://forum.electromage.com/u/zranger1)\
**Post date:** [December 7, 2020, 1:28am UTC](https://forum.electromage.com/t/pixelblaze-client-python-3-library-for-pixelblaze/756/28 "2020-12-07T01:28:33Z")

</div>

Just updated to v0.9, which includes the new **PixelblazeEnumerator** class. It listens continuously for Pixelblaze beacon packets, maintains a list of Pixelblazes visible on the network and supports synchronizing time on multiple Pixelblazes. The essential API looks like this:

- PixelblazeEnumerator(bind\_ip=“0.0.0.0”) - Create an object that will listen for Pixelblazes on IP address bind\_ip, or all available interfaces if bind\_ip is not specified.
- getPixelblazeList() - Return a list of the IP addresses of Pixelblazes that are currently visible on the network
- synchronize() - Set the time on all currently visible Pixelblazes to match time on the sending computer.

plus several more methods to control timouts, automatic synchronization, shutdown, etc. Documentation and sample code are in the repository.

Unless we find a showstopping bug, or a necessary feature that got left out, the pixelblaze-client library is now feature complete. I’m going to move ahead with getting it published on PyPi this week. Hope lots of people use this, and have fun making amazing things!

---

<div class="post-metadata">

**Author:** ![wizard](https://forum.electromage.com/user_avatar/forum.electromage.com/wizard/32/4_2.png) [@wizard](https://forum.electromage.com/u/wizard)\
**Post date:** [December 7, 2020, 5:17pm UTC](https://forum.electromage.com/t/pixelblaze-client-python-3-library-for-pixelblaze/756/29 "2020-12-07T17:17:55Z")

</div>

Hi @zranger1,  
Awesome!

For timesync stuff, the reply should go out right as soon as the beacon is heard. The latency should be as low as possible and as consistent as possible. Pixelblaze uses many of these over time to figure out the round trip time and half the median RTT is used to get it stable within a few ms. Similar to [NTP’s clock sync algorithm](https://en.wikipedia.org/wiki/Network_Time_Protocol#Clock_synchronization_algorithm).

So think of it more of a mode than a one time sync. Should it reply or not?

Only one node should reply on a network. I don’t yet have an election process to prevent multiple replies (or from handling multiple replies), and if there are things can get glitchy. Right now it’s assumed that either there will be only one Firestorm / pixeblaze-client w/ timesync mode on, or that a PB in AP mode can reply.

---

<div class="post-metadata">

**Author:** ![zranger1](https://forum.electromage.com/user_avatar/forum.electromage.com/zranger1/32/301_2.png) [@zranger1](https://forum.electromage.com/u/zranger1)\
**Post date:** [December 7, 2020, 5:37pm UTC](https://forum.electromage.com/t/pixelblaze-client-python-3-library-for-pixelblaze/756/30 "2020-12-07T17:37:44Z")

</div>

It looked like NTP, but in testing here, the 5 second interval didn’t seem to make much difference, so I left it that way to control wifi traffic. In retrospect, that’s because in my particular situation – doh! around 1ms RTT, no appreciable jitter on the LAN.

I’ll get rid of the explicit synchronize() API, and set it up so that enabling synchronization responds to every beacon packet. I didn’t see any election-like traffic, so I just “borrowed” firestorm’s ID, assuming that it was always the one in charge.

Is it worth watching for other timesync packets, and deferring to any other time source that’s already sending? At this stage, this is all easy stuff to implement.

---

<div class="post-metadata">

**Author:** ![wizard](https://forum.electromage.com/user_avatar/forum.electromage.com/wizard/32/4_2.png) [@wizard](https://forum.electromage.com/u/wizard)\
**Post date:** [December 7, 2020, 6:25pm UTC](https://forum.electromage.com/t/pixelblaze-client-python-3-library-for-pixelblaze/756/31 "2020-12-07T18:25:09Z")

</div>

It uses the time since beacon to timesync to determine the offset, so I would expect that if you booted a handful of PB at different intervals, and were sending timesync every 5s to everything, the’d get weird offsets like 0-2.5s depending on how that lined up.

There isn’t anything special about Firestorm’s ID, other than it’s Firestorm’s ID. Feel free to pick a random 32 bit number, or choose a favorite number. It would be good to choose a different one than Firestorm for network debugging purposes.

Yeah, deferring to another source is one way to elect a leader. If all timesync sources used the same algorithm, like defer to lower ID sources if heard within 10s or something. I planed to read up a bit more on election algorithms before doing anything like that just to make sure I’m not falling into some known traps.

I could also make PBs smarter, so they focus on a specific source, but it’s still better to have fewer packets flying around.

---

<div class="post-metadata">

**Author:** ![zranger1](https://forum.electromage.com/user_avatar/forum.electromage.com/zranger1/32/301_2.png) [@zranger1](https://forum.electromage.com/u/zranger1)\
**Post date:** [December 7, 2020, 6:34pm UTC](https://forum.electromage.com/t/pixelblaze-client-python-3-library-for-pixelblaze/756/32 "2020-12-07T18:34:12Z")

</div>

Cool… I’ll make all these changes and get it checked in. At this point, I’ll have it defer to any other time source. Will just leave a note in the code that at some point we might want to compare IDs and give lower numbered sources priority.

I did browsemaster election for NetBIOS/SMB networks a very long time ago. It was (and still is) pretty hairy. If things are working as they are, not much reason to add complication at the moment.

---

<div class="post-metadata">

**Author:** ![zranger1](https://forum.electromage.com/user_avatar/forum.electromage.com/zranger1/32/301_2.png) [@zranger1](https://forum.electromage.com/u/zranger1)\
**Post date:** [December 7, 2020, 7:42pm UTC](https://forum.electromage.com/t/pixelblaze-client-python-3-library-for-pixelblaze/756/33 "2020-12-07T19:42:51Z")

</div>

Done!  
PixelblazeEnumerator now responds with timesync packets on every beacon as quickly as possible. The old “synchronize(),enable/disable autosync” API gone, the new one is just:

- enableTimesync() - start synchronization
- disableTimesync() - stop synchronization

Synchronization is off by default. The user must call enableTimesync() to start it. Once started, if it detects another time source on the network, it will automatically defer. The default senderID for pixelblaze-client is now 890 - if there’s an eventual lower-id–has-priority scheme, it’s 1 level below Firestorm.

… back to working on outdoor lights for me! …

---

<div class="post-metadata">

**Author:** ![zranger1](https://forum.electromage.com/user_avatar/forum.electromage.com/zranger1/32/301_2.png) [@zranger1](https://forum.electromage.com/u/zranger1)\
**Post date:** [December 17, 2020, 3:25am UTC](https://forum.electromage.com/t/pixelblaze-client-python-3-library-for-pixelblaze/756/34 "2020-12-17T03:25:54Z")

</div>

Ok! The pixelblaze-client package is now available on pypi. To install, just  
`pip install pixelblaze-client`  
and use  
` import pixelblaze`  
or  
`from pixelblaze import *`  
in your programs.

Sample code is in the “examples” directory in the repository, and API documentation is still in README.md

First time publishing anything there – my main use of Python to date has been for short one-off data analysis scripts. So:

- Yay, it worked! It’s up there and available to the general public!
- Let me know if you encounter any problems.
- Have fun making cool things!

---

<div class="post-metadata">

**Author:** ![zranger1](https://forum.electromage.com/user_avatar/forum.electromage.com/zranger1/32/301_2.png) [@zranger1](https://forum.electromage.com/u/zranger1)\
**Post date:** [January 16, 2021, 9:55pm UTC](https://forum.electromage.com/t/pixelblaze-client-python-3-library-for-pixelblaze/756/35 "2021-01-16T21:55:56Z")

</div>

Just posted a minor update to pixelblaze-cllient. It’s available on pypi now.

This version adds support for the new sequencer features in the latest Pixelblaze firmware. Specifically:

`startSequencer()` now takes a “mode” parameter, which sets the sequencer’s operating mode: 1 - Shuffle, 2 - Playlist. You still have to use the Web UI to set up your playlist (for now).

I’ve added methods to pause and restart the sequencer without losing your place in the current shuffle or playlist. They are:  
`pauseSequencer()` and `playSequencer()`

`stopSequencer()` still stops and disables the sequencer, regardless of mode.

Full documentation is available on pypi, or from the repository’s readme. I’ve been meaning to get this checked in for a while, but it’s just been the Season of Way Too Many Projects…

---

<div class="post-metadata">

**Author:** ![zranger1](https://forum.electromage.com/user_avatar/forum.electromage.com/zranger1/32/301_2.png) [@zranger1](https://forum.electromage.com/u/zranger1)\
**Post date:** [February 7, 2022, 11:56pm UTC](https://forum.electromage.com/t/pixelblaze-client-python-3-library-for-pixelblaze/756/36 "2022-02-07T23:56:36Z")

</div>

I’ve updated the pixelblaze-client library to v0.9.4. It’s available on [Github](https://github.com/zranger1/pixelblaze-client) and [pypi](https://pypi.org/project/pixelblaze-client/) now.

This is the “small step now before we take a huge step later” release. There are bug fixes, performance improvements, a few new commands and some behavior changes aimed at reducing unneeded writes to flash memory.

Here are the details:

- Documented getPixelCount/setPixelCount(), which lets you get and set the number of LEDs attached to your Pixelblaze.
- added the pause() and unpause() commands.
- getPatternList() is now cached, for greatly improved performance. The cache timeout can be set by calling setCacheRefreshTime(seconds). The default is 600 seconds, or 10 minutes.
- Reduced unneccessary flash writes - setActivePattern(), setActivePatternId() and setBrightness() now take  
an optional saveFlash parameter, which is False by default, and uses the enable\_flash\_save() safety  
mechanism (described in the API documentation) to prevent inadvertent flash saves.

If you’re a Python user, try this out and let me know how it works for you!

---

<div class="post-metadata">

**Author:** ![pixie](https://forum.electromage.com/letter_avatar_proxy/v4/letter/p/7bcc69/32.png) [@pixie](https://forum.electromage.com/u/pixie)\
**Post date:** [July 16, 2022, 3:52pm UTC](https://forum.electromage.com/t/pixelblaze-client-python-3-library-for-pixelblaze/756/37 "2022-07-16T15:52:56Z")

</div>

Pull request: If you change the signature of `ws_recv` to:

```auto
    def ws_recv(self, wantBinary=False, packetType=0x07):

```

and the test for binary packets to:

```auto
                elif (wantBinary is True) and (result[0] == packetType): # binary pattern list packet

```

then your library can be used to read other things besides the pattern list (I’m redoing my [animated previews](https://forum.electromage.com/t/feature-request-raw-rgb-values-in-preview-jpg/1791/5) code to take advantage of the increased number of preview pixels in v3.24, but they’re only in the websocket packets – the preview jpeg saved inside the pattern EPE is still limited to 100 wide by 150 tall).

---

<div class="post-metadata">

**Author:** ![zranger1](https://forum.electromage.com/user_avatar/forum.electromage.com/zranger1/32/301_2.png) [@zranger1](https://forum.electromage.com/u/zranger1)\
**Post date:** [July 16, 2022, 4:27pm UTC](https://forum.electromage.com/t/pixelblaze-client-python-3-library-for-pixelblaze/756/38 "2022-07-16T16:27:34Z")

</div>

Thanks! Will get this in this afternoon, and into pypi asap!

If you’ve got a github account, pm me with your github name and I’ll add you as a collaborator on the python client repo so you can check things like this in as you encounter them.

---

<div class="post-metadata">

**Author:** ![zranger1](https://forum.electromage.com/user_avatar/forum.electromage.com/zranger1/32/301_2.png) [@zranger1](https://forum.electromage.com/u/zranger1)\
**Post date:** [July 16, 2022, 7:49pm UTC](https://forum.electromage.com/t/pixelblaze-client-python-3-library-for-pixelblaze/756/39 "2022-07-16T19:49:27Z")

</div>

Ok - @pixie’s improvement is in! pixelblaze-client v0.9.5 is updated in the repo and available for download on pypi.

---

<div class="post-metadata">

**Author:** ![awakebyjava](https://forum.electromage.com/user_avatar/forum.electromage.com/awakebyjava/32/1930_2.png) [@awakebyjava](https://forum.electromage.com/u/awakebyjava)\
**Post date:** [September 27, 2022, 7:36pm UTC](https://forum.electromage.com/t/pixelblaze-client-python-3-library-for-pixelblaze/756/40 "2022-09-27T19:36:41Z")

</div>

Hello! I’ve been using the client to run my project, but i just updated to v0.9.5 and it seems like a few things have changed enough that it broke, and I can’t find documentation that’s helpful.

I’m getting a message about the difference between setActivePattern(name\_or\_id) and setActivePattern(id). I’m not fluent enough to understand what has changed and why my code isn’t working. The examples seem to be broken as well, so I’m kind of at a loss.

Thanks so much!

[Previous page](https://forum.electromage.com/t/pixelblaze-client-python-3-library-for-pixelblaze/756.md?page=1)

[Next page](https://forum.electromage.com/t/pixelblaze-client-python-3-library-for-pixelblaze/756.md?page=3)
