Ninjablocks

When you enter the command : sudo chmod +x
Are you in the same dir as the file?..
If you followed my line, the ninjabridge file is in the /root directory.
You should be in that dir (as root) to fire the command.
-su (to become root)
-cd /root (to go to the dir where the bridge file is

So I was able to get that part to work.

It appears everything works until I type in service mqttbridge start I get the error:

Failed to start mqttbridge.service: The name org.freedesktop.PolicyKit1 was not provided by any .service files
See system logs and 'systemctl status mqttbridge.service' for details.

As I wrote above, I had been following instructions as if they were prescriptive.

Forget About the mqtt bridge service. I think it will work if you try this:

I wonder if someone could assist me with ninjaCapeSerialMQTTBridge.py script - I’ve followed the instructions above and installed it successfully. The problem I’m having is when it runs on start it sometimes errors with the following:
Traceback (most recent call last):
File “/usr/lib/python2.7/threading.py”, line 810, in __bootstrap_inner
self.run()
File “/usr/lib/python2.7/threading.py”, line 763, in run
self.__target(*self.__args, **self.__kwargs)
File “./ninjaCapeSerialMQTTBridge.py”, line 85, in serial_read_and_publish
json_data = json.loads(line)
File “/usr/lib/python2.7/json/init.py”, line 338, in loads
return _default_decoder.decode(s)
File “/usr/lib/python2.7/json/decoder.py”, line 366, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File “/usr/lib/python2.7/json/decoder.py”, line 384, in raw_decode
raise ValueError(“No JSON object could be decoded”)
ValueError: No JSON object could be decoded

If I try running it again it will sometimes continue are run successfully. But after a restart usually hangs and doesn’t carry on.

Any ideas?

Are there any ways to test to see if the program is running or even get a stream of data off the ninjablock serial port?

I have tried this but receive nothing.
mosquitto_sub -d -u myname -P mypass -t ninjaCape/input/#

Background.
mqtt is running on BBB that was a ninjablock with fresh linux on it. I can send stuff to it from my hassio running on pi3 no probs.

I am using the 1gb stretch-console as my BBB is the earlier 2gb model. Seems to have installed everything fine (there where a few additional things like java, python and curl I had to add as well on this version).

I have also looked at serial port issue as it seems the ninja uses ttyO1 that is not enabled by default.
a link I saw by the node red guys suggested this http://beaglebone.cameon.net/home/serial-ports-uart

Wow its been 6 months since I tried this…never reply back …still WIP…
I did everything you mentioned up to the password/login for the mqtt…currently stuck at:

service mqttbridge start

Returns:

Failed to start mqttbridge.service: The name org.freedesktop.PolicyKit1 was not provided by any .service files
See system logs and 'systemctl status mqttbridge.service' for details.

I tried sudo, sudo su… I did change the settings within the ninjaCape…py to work on my cape with the pi…ttyAMA0…and also the mqttbridge.conf as follow:

mqttbridge.conf:
where it says “ubuntu” to “pi”… without quotes…
did not changed anything else.

I tried the “put in rc.local” also ran:

sudo cat </etc/rc.local
#!/bin/sh -e
#By default this script does nothing.
exit 0
EOF

sudo chmod +x /etc/rc.local
sudo systemctl start rc-local
sudo systemctl status rc-local

Tried rebooting several times and also tried running the ninjaCape…py while starting the service…FAILED! :frowning:

HELP

I am having trouble getting my senors to show up. I ran mosquitto_sub -d -t "ninjaCape/input/#" and it gives me the following;

EDIT: Unplugging the Cape gives me the same result below. So I am pretty sure the cape is not talking to mqtt service.

Client mosqsub/7945-beaglebone sending CONNECT
Client mosqsub/7945-beaglebone received CONNACK
Client mosqsub/7945-beaglebone sending SUBSCRIBE (Mid: 1, Topic: ninjaCape/input/#, QoS: 0)
Client mosqsub/7945-beaglebone received SUBACK
Subscribed (mid: 1): 0
Client mosqsub/7945-beaglebone sending PINGREQ
Client mosqsub/7945-beaglebone received PINGRESP

I never see any devices pop up. Is there any way of verifying that the BBB is talking to the NinjaCape?

Yay! I figured it out. I had to add the following to my ‘uEnv.txt’ file and reboot;

dtb_overlay=/lib/firmware/BB-UART1-00A0.dtbo

I think I had to do this because I was running off of a fresh install of Debian 9.3 and not the NinjaBlocks image.

EDIT: I forgot I had to add ‘.encode()’ to the ‘/root/ninjaCapeSerialMQTTBridge.py’ file also. Python 3 throws an error without it.

while True: # main thread
            #writing to serial port if there is data available
            if( len(outputData) > 0 ):
                    #print "***data to OUTPUT:",mqtt_to_JSON_output(outputData[0])
                    # Add .encode() to line below;
                    ser.write(mqtt_to_JSON_output(outputData.pop()).encode())

            time.sleep(0.5)
1 Like

I had this same issue using a fresh install of debian v9.3 (stretch?). I read somewhere that rc.local is no longer used and had no luck with re-enabling it. I ended up making a systemd service for the mqttbridge. I did the following;

  1. Create a new service file; sudo nano -w /etc/systemd/system/mqttbridge.service

  2. Copy the following to it;

    [Unit]
    Description=MQTT Bridge
    After=multi-user.target

    [Service]
    Type=idle
    ExecStart=/usr/bin/python /root/ninjaCapeSerialMQTTBridge.py
    Restart=on-failure

    [Install]
    WantedBy=multi-user.target

  3. Run the follow to update systemd with new service;

    sudo systemctl --system daemon-reload
    sudo systemctl enable mqttbridge
    sudo reboot

Hi everyone, back at it again… soooo…I decided to get a RPi3… it seems to have more pins that my old RPi (it does!) lol.
Q: I read the pins are the same if connecting the cape, the rest or empty ones are just extra? meaning I can still use my cape with the RPi3, right?
Just double checking if anyone has done this.

Havent use my cape in over a year and now need the 433 temp device readings from my ninjablock within HA and not sure if this is going to work.

why am I get this error even with your hint with .encode

Connecting...  /dev/ttyO1
Connected
Subscribed. mid: 1
Output Data:  ninjaCape/output/110 data: b'000001010101010100111100'
Traceback (most recent call last):
  File "/root/ninjaCapeSerialMQTTBridge-test.py", line 131, in <module>
    ser.write(mqtt_to_JSON_output(outputData.pop()))
  File "/root/ninjaCapeSerialMQTTBridge-test.py", line 69, in mqtt_to_JSON_output
    json_data = '{"DEVICE": [{"G":"0","V":0,"D":' + topics[2] + ',"DA":"' + mqtt_message.payload + '"}]})'
TypeError: can only concatenate str (not "bytes") to str

Could there be write protection on that file and adding .encode did not save? I ask because the error you show does not have it and you can see that the data cannot be concatenated because it is still in bytes (needs to be string).

I no longer use the ninjacape so I am not sure how much I can help.