todbot / blink1-tool

Command-line tools and C library for blink(1) USB RGB LED
https://blink1.thingm.com/
Other
84 stars 15 forks source link

Blink1 not working on raspberry pi 4. #51

Closed mechengineermike closed 2 years ago

mechengineermike commented 2 years ago

pi@raspberrypi:~ $ git clone https://github.com/todbot/blink1-tool.git Cloning into 'blink1-tool'... remote: Enumerating objects: 10681, done. remote: Counting objects: 100% (225/225), done. remote: Compressing objects: 100% (145/145), done. remote: Total 10681 (delta 110), reused 151 (delta 56), pack-reused 10456 Receiving objects: 100% (10681/10681), 79.74 MiB | 10.24 MiB/s, done. Resolving deltas: 100% (5610/5610), done. pi@raspberrypi:~ $ cd blink1-tool pi@raspberrypi:~/blink1-tool $ make Building blink1-tool for OS=linux BLINK1_VERSION=v2.2.0-linux-armv7l USBLIB_TYPE=HIDAPI Type 'make help' for other build products Submodule 'hidapi' (https://github.com/libusb/hidapi.git) registered for path 'hidapi' Cloning into '/home/pi/blink1-tool/hidapi'... Submodule path 'hidapi': checked out 'f6d0073fcddbdda24549199445e844971d3c9cef' gcc -Wall -Wno-format -Wno-pointer-to-int-cast -DUSE_HIDAPI -I./hidapi/hidapi -fPIC -Wall -std=gnu99 -DBLINK1_VERSION=\"""v2.2.0"-linux-"armv7l""\" -c hidapi/linux/hid.c -o hidapi/linux/hid.o hidapi/linux/hid.c:44:10: fatal error: libudev.h: No such file or directory

include

      ^~~~~~~~~~~

compilation terminated. make: *** [Makefile:573: hidapi/linux/hid.o] Error 1

I literally just want to use python to visit the web url to activate spcific colors. Easiest thing. Works on my PC, but the device does not respond on the pi

mechengineermike commented 2 years ago

update: running sudo apt-get install libusb* got me past that problem. On to the next one

todbot commented 2 years ago

Hi, On Linux, there are some requirements to install, just like most all Linux projects. The build requirements are listed here, with relevant commands to install them: https://github.com/todbot/blink1-tool#linux-debian-flavored

Or you can download a pre-compiled version for Raspberry Pi: https://github.com/todbot/blink1-tool/releases/tag/v2.2.0

Also, be sure to set up the udev rules in case you want to run blink1-tool: https://github.com/todbot/blink1-tool#linux-including-raspberry-pi

Apologies if this wasn't clear.

todbot commented 2 years ago

Also, since the README and build process failed you, what could we change to make it more clear?

mechengineermike commented 2 years ago

I just got it working using your precompiled version. Also of note that the server host on the pi defaulted to port 8000, instead of the 8934 port that it uses on windows.

My IDEAL experience:

  1. "sudo pip install blink1" #complete set of packages installed, print(Ready to go dude!)
  2. Auto start the web server by default when the blink1 device gets plugged in. The web server is the most powerful feature for my use since I can trigger the action I want from anywhere on my network just by visiting a specific url (or with curl).
  3. The webserver could host a very simple web1.0 style html gui with a few buttons, the ID info, & the color picker. (the color pattern feature is glitchy & if I want a pattern I can achieve that via changing the timing & contents of my curl commands.) :) Overall despite my apparent frustration in the comment above the product looks great and I would recommend it to friends. At $30 its way cheaper than industrial ANDON lights.
todbot commented 2 years ago

The Blink1Control2 app's HTTP API server runs on port 8934. The blink1-tiny-server app runs on port 8000, is that what you mean? They are different applications so we went with different ports. This has been a point of confusion though so perhaps we should change this so they're all on port 8934.

To your points:

  1. I would love for pip install blink1 to work out of the box for all OSes. Unfortunately, Python community support for native packages across all platforms is limited at best. I would love to know what your issues were with the Python package. I assume it was because it couldn't find hidapi, which the Python folks think should be installed by the OS's package manager.

  2. Most of our customers do not want a daemon automatically installed on their systems when installing any blink1 software. (which is what I assume you're describing) The blink1-tiny-server will automatically start using a blink(1) when it's plugged in, but hotplug support real mess, on any OS.

  3. This is a really good idea. And I had totally forgotten we have the start of that as described in server/README.md. But it's incredibly rudimentary and didn't get farther because of the problem of packaging up the GUI with the binary as a single file. (The blink1-tiny-server program has the requirement of being as minimal as possible to fit on micro Linuxes) This would be a great place for Python to shine, and if I can get the upstream blink1-python requirements to be fully installed, having a full-featured Python-based server would be really nice.

Thanks for being a customer. We are very small and try to make it all just work but sometimes that doesn't happen. Thank you for being patient.

mechengineermike commented 2 years ago

Yes thats what I mean. I guess i dont understand the difference between the tiny & full versions but i'd think it would be OK to run the tiny server on a pi at the same time as the full server version on a pc both on port 8934 and they wouldn't interfere since the host devices would have different IPs.

1 copied response below. Ive no idea how to troubleshoot that and my needs are satisfied but thought it might be useful.

2. I see, I was confused, np that you have to run a command line to begin the server.

3 for a python based server, def check this out: https://gist.github.com/UniIsland/3346170 Im using a modified version of it for a few of my own projects. (http://cylindraw.ddns.net:8080/)

from #1, on raspberry pi 4, stock noobs installed raspbian OS latest version as of Nov2021. pi@raspberrypi:~ $ pip install blink1 Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple Collecting blink1 Collecting hidapi>=0.7.99 (from blink1) Using cached https://files.pythonhosted.org/packages/dc/aa/38708a1d85d13dec22e756feb4e02f8b3adc5937bfe976f8f998717ff0a3/hidapi-0.11.0.post2.tar.gz Requirement already satisfied: click in /usr/lib/python2.7/dist-packages (from blink1) (7.0) Collecting webcolors (from blink1) Using cached https://files.pythonhosted.org/packages/8b/ff/c21df7e08e68a1a84b947992c07dfed9cfe7219d068cb7728358d065c877/webcolors-1.10-py2.py3-none-any.whl Requirement already satisfied: setuptools>=19.0 in /usr/lib/python2.7/dist-packages (from hidapi>=0.7.99->blink1) (40.8.0) Requirement already satisfied: six in /usr/lib/python2.7/dist-packages (from webcolors->blink1) (1.12.0) Building wheels for collected packages: hidapi Running setup.py bdist_wheel for hidapi ... error Complete output from command /usr/bin/python -u -c "import setuptools, tokenize;file='/tmp/pip-install-Eywk_L/hidapi/setup.py';f=getattr(tokenize, 'open', open)(file);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, file, 'exec'))" bdist_wheel -d /tmp/pip-wheel-990J72 --python-tag cp27: running bdist_wheel running build running build_ext skipping 'hid.c' Cython extension (up-to-date) skipping 'hidraw.c' Cython extension (up-to-date) building 'hid' extension creating build creating build/temp.linux-armv7l-2.7 creating build/temp.linux-armv7l-2.7/hidapi creating build/temp.linux-armv7l-2.7/hidapi/libusb arm-linux-gnueabihf-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fdebug-prefix-map=/build/python2.7-InigCj/python2.7-2.7.16=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC -Ihidapi/hidapi -I/usr/include/libusb-1.0 -I/usr/include/python2.7 -c hid.c -o build/temp.linux-armv7l-2.7/hid.o hid.c: In function \u2018pyx_pf_3hid_6device_open\u2019: hid.c:3518:45: warning: passing argument 1 of \u2018PyUnicodeUCS4_AsWideChar\u2019 from incompatible pointer type [-Wincompatible-pointer-types] __pyx_v_result = PyUnicode_AsWideChar(pyx_v_serial_number, __pyx_v_cserial_number, __pyx_v_serial_len); ^~~~~ In file included from /usr/include/python2.7/Python.h:88, from hid.c:16: /usr/include/python2.7/unicodeobject.h:592:22: note: expected \u2018PyUnicodeObject \u2019 {aka \u2018struct \u2019} but argument is of type \u2018PyObject \u2019 {aka \u2018struct _object \u2019} PyUnicodeObject unicode, / Unicode object */


  arm-linux-gnueabihf-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fdebug-prefix-map=/build/python2.7-InigCj/python2.7-2.7.16=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC -Ihidapi/hidapi -I/usr/include/libusb-1.0 -I/usr/include/python2.7 -c hidapi/libusb/hid.c -o build/temp.linux-armv7l-2.7/hidapi/libusb/hid.o
  creating build/lib.linux-armv7l-2.7
  arm-linux-gnueabihf-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-z,relro -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -Wdate-time -D_FORTIFY_SOURCE=2 -g -fdebug-prefix-map=/build/python2.7-InigCj/python2.7-2.7.16=. -fstack-protector-strong -Wformat -Werror=format-security -Wl,-z,relro -Wdate-time -D_FORTIFY_SOURCE=2 -g -fdebug-prefix-map=/build/python2.7-InigCj/python2.7-2.7.16=. -fstack-protector-strong -Wformat -Werror=format-security build/temp.linux-armv7l-2.7/hid.o build/temp.linux-armv7l-2.7/hidapi/libusb/hid.o -lusb-1.0 -ludev -lrt -o build/lib.linux-armv7l-2.7/hid.so
  /usr/bin/ld: cannot find -ludev
  collect2: error: ld returned 1 exit status
  error: command 'arm-linux-gnueabihf-gcc' failed with exit status 1

  ----------------------------------------
  Failed building wheel for hidapi
  Running setup.py clean for hidapi
Failed to build hidapi
Installing collected packages: hidapi, webcolors, blink1
  Running setup.py install for hidapi ... error
    Complete output from command /usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-Eywk_L/hidapi/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-record-n_N3X0/install-record.txt --single-version-externally-managed --compile --user --prefix=:
    running install
    running build
    running build_ext
    skipping 'hid.c' Cython extension (up-to-date)
    skipping 'hidraw.c' Cython extension (up-to-date)
    building 'hid' extension
    creating build
    creating build/temp.linux-armv7l-2.7
    creating build/temp.linux-armv7l-2.7/hidapi
    creating build/temp.linux-armv7l-2.7/hidapi/libusb
    arm-linux-gnueabihf-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fdebug-prefix-map=/build/python2.7-InigCj/python2.7-2.7.16=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC -Ihidapi/hidapi -I/usr/include/libusb-1.0 -I/usr/include/python2.7 -c hid.c -o build/temp.linux-armv7l-2.7/hid.o
    hid.c: In function \u2018__pyx_pf_3hid_6device_open\u2019:
    hid.c:3518:45: warning: passing argument 1 of \u2018PyUnicodeUCS4_AsWideChar\u2019 from incompatible pointer type [-Wincompatible-pointer-types]
           __pyx_v_result = PyUnicode_AsWideChar(__pyx_v_serial_number, __pyx_v_cserial_number, __pyx_v_serial_len);
                                                 ^~~~~~~~~~~~~~~~~~~~~
    In file included from /usr/include/python2.7/Python.h:88,
                     from hid.c:16:
    /usr/include/python2.7/unicodeobject.h:592:22: note: expected \u2018PyUnicodeObject *\u2019 {aka \u2018struct <anonymous> *\u2019} but argument is of type \u2018PyObject *\u2019 {aka \u2018struct _object *\u2019}
         PyUnicodeObject *unicode,   /* Unicode object */
         ~~~~~~~~~~~~~~~~~^~~~~~~
    arm-linux-gnueabihf-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fdebug-prefix-map=/build/python2.7-InigCj/python2.7-2.7.16=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC -Ihidapi/hidapi -I/usr/include/libusb-1.0 -I/usr/include/python2.7 -c hidapi/libusb/hid.c -o build/temp.linux-armv7l-2.7/hidapi/libusb/hid.o
    creating build/lib.linux-armv7l-2.7
    arm-linux-gnueabihf-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-z,relro -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -Wdate-time -D_FORTIFY_SOURCE=2 -g -fdebug-prefix-map=/build/python2.7-InigCj/python2.7-2.7.16=. -fstack-protector-strong -Wformat -Werror=format-security -Wl,-z,relro -Wdate-time -D_FORTIFY_SOURCE=2 -g -fdebug-prefix-map=/build/python2.7-InigCj/python2.7-2.7.16=. -fstack-protector-strong -Wformat -Werror=format-security build/temp.linux-armv7l-2.7/hid.o build/temp.linux-armv7l-2.7/hidapi/libusb/hid.o -lusb-1.0 -ludev -lrt -o build/lib.linux-armv7l-2.7/hid.so
    /usr/bin/ld: cannot find -ludev
    collect2: error: ld returned 1 exit status
    error: command 'arm-linux-gnueabihf-gcc' failed with exit status 1

    ----------------------------------------
Command "/usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-Eywk_L/hidapi/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-record-n_N3X0/install-record.txt --single-version-externally-managed --compile --user --prefix=" failed with error code 1 in /tmp/pip-install-Eywk_L/hidapi/
pi@raspberrypi:~ $ 
todbot commented 2 years ago

Oh man Python can be such a headache.

Looks like you're dealing with Python2 vs Python3 problems in addition to anything blink1 is bringing to the party. This is when I just close the laptop and go get some coffee.

I'll do some more research on Python native packages and thanks for the link to the server.

mechengineermike commented 2 years ago

Just revisited this 6 months later and ran through the whole silly process of figuring it out again. To help anyone else out there as clueless as me (or just myself again in 6 months) its really easy.

  1. On your pi visit https://github.com/todbot/blink1-tool/releases/download/v2.2.0/blink1-tiny-server-v2.2.0-linux-armv7l.zip
  2. extract that file somewhere accessible. (say, /home/pi/Desktop/blink1-tiny-server)
  3. Make a new python program say LED_BLINK.py also on the desktop and put in it everything below.
  4. To run this call from the command line: sudo python3 /home/pi/Desktop/LED_BLINK.py
#!/usr/bin/env python3
import os
import time
import subprocess as serverHost 
import subprocess as ping

PORT = 8000
baseCmd = 'http://localhost:'+str(PORT) +'/blink1/' 

try:    
   print('attempting to start blink1 server Host...')
   cmd = 'sudo /home/pi/Desktop/blink1-tiny-server'
   p = serverHost.Popen(cmd,shell=True) #cd /home/pi/Desktop/database/public;//"exec " +
   time.sleep(2)
except Exception as ex:
    print('assuming server is already running...')
    template = "   ~An exception of type *{0}* occurred. Arguments: {1!r}"
    message = template.format(type(ex).__name__, ex.args)
    print (message)
    pass

result = os.popen('curl '+baseCmd +'green').read()  
time.sleep(1) 
result = os.popen('curl '+baseCmd +'fadeToRGB?rgb=#000000').read()
time.sleep(1)
result = os.popen('curl '+baseCmd +'green').read()  
time.sleep(1) 
result = os.popen('curl '+baseCmd +'fadeToRGB?rgb=#000000').read()
time.sleep(1)
result = os.popen('curl '+baseCmd +'green').read()  
time.sleep(1) 
result = os.popen('curl '+baseCmd +'fadeToRGB?rgb=#000000').read()
time.sleep(1)

#http://localhost:8000/blink1/ #- simple status page
#Alternate commands
#fadeToRGB?rgb=#000000     #OFF
#id #- get blink1 serial number
#on #- turn blink(1) full bright white
#red #- turn blink(1) solid red
#green #- turn blink(1) solid green
#blue #- turn blink(1) solid blue
#fadeToRGB #- turn blink(1) specified RGB color
#blink #- blink the blink(1) the specified RGB color
#pattern/play #- play color pattern specified by 'pattern' arg
#random #- turn the blink(1) a random color
todbot commented 2 years ago

This is really helpful @mechengineermike, thanks!