Author Topic: beacon_decode.py issue  (Read 471 times)

wxhzk

  • Newbie
  • *
  • Posts: 5
    • View Profile
beacon_decode.py issue
« on: January 23, 2017, 06:09:18 pm »
When I trying to run the python program to decode beacon, it says
rssi = struct.unpack("b",rssi_part)[0] Type Error: A byte-like object is required, not 'str'

Anyone can help me to solve this??? Thanks in advance

Share on Facebook Share on Twitter


Nick_W

  • Full Member
  • ***
  • Posts: 215
    • View Profile
Re: beacon_decode.py issue
« Reply #1 on: January 23, 2017, 08:37:41 pm »
Are you running Python 3? This is a Python 2.7 program.

Python 3 uses byte arrays in place of the Python 2.7 strings. Should be fairly easy to fix, but I don't think I have Python 3 installed anywhere.

I'll see what I can do.

Nick_W

  • Full Member
  • ***
  • Posts: 215
    • View Profile
Re: beacon_decode.py issue
« Reply #2 on: January 23, 2017, 08:46:10 pm »
This describes the behaviour of Python 3.5 http://stackoverflow.com/questions/35249879/python-struct-unpack-errors-with-typeerror-a-bytes-like-object-is-required-not

And gives the fix. I'll see if I can fix it, but it'll be hard to test without having Python 3.5 installed.

wxhzk

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: beacon_decode.py issue
« Reply #3 on: January 24, 2017, 11:44:19 am »
You are totally right. Using Python 2.7 solve the issue.

wxhzk

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: beacon_decode.py issue
« Reply #4 on: January 24, 2017, 12:45:19 pm »
Now, it can decode and save it to log file, but I wonder how can I run the decode program on the cloud mqtt end, so that I can get decoded info to my cell phone.

Nick_W

  • Full Member
  • ***
  • Posts: 215
    • View Profile
Re: beacon_decode.py issue
« Reply #5 on: January 24, 2017, 01:41:15 pm »
The beacon_decode.py program actually rebroadcasts the decoded beacons via MQTT. The log is just so that you can see what is going on.

If you look at the command line options, one of them is --topic (-t) which is the MQTT topic that the decoded beacons are sent to. Default is MCThings/

So each beacon is received, decoded and published to MCThings/<beacond_id>/<item> where <beacon id> is the same as what was received, and <item> is what the value was decoded as (Temperature, BatteryVoltage, Humidity etc.).

You can change --topic to whatever you want on the command line. If you leave it as default and subscribe on your computer to MCThings/# you should see all your modules data being published (decoded from beacons). To publish to the cloud, add this to the command line:

Code: [Select]
beacon_decode.py -t cloud_topic_whatever/whatever/whatever/

Where cloud_topic_whatever is where you publish things to see them on your phone. You can specify other command line options for broker, port, user_id and password - this assumes that you are receiving and sending to the same broker. If they are different, the program would need to be modified to have two mqtt brokers, ports, users, passwords etc. Easy enough to do, but I was assuming you would just use the one broker.

Data then shows up on  cloud_topic_whatever/whatever/whatever/<beacond_id>/<item> as previously described.


The log is just so that you can see what is happening.
« Last Edit: January 24, 2017, 01:50:44 pm by Nick_W »

Nick_W

  • Full Member
  • ***
  • Posts: 215
    • View Profile
Re: beacon_decode.py issue
« Reply #6 on: January 24, 2017, 02:33:40 pm »
OK,

Just pushed new version of beacon_decode.py which allows the setting of two different brokers, one the source, and one the destination. Destination in optional, program will always publish back to the source, but now you can optionally publish to a second broker, defined using command line options for:

destbroker
destport
destuser
destpassword
destclientid

Hope this helps the people wanting to decode/receive locally, but publish to the cloud.