Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ble2mqtt unable to read data to and from file #1

Open
shakilbharucha opened this issue Jun 4, 2019 · 5 comments
Open

ble2mqtt unable to read data to and from file #1

shakilbharucha opened this issue Jun 4, 2019 · 5 comments

Comments

@shakilbharucha
Copy link

Dear Team,

I have a GX-750 Modem and I was able to install the bletool_1-2_mips_24kc.ipk and get the data on the console.
I am trying to push ble data to my own mqtt server. However, in this script, i am only trying to store date to and read from the file blesnipper. However, the data that gets written is a 'ok' message in the file.

Help needed to resolve this, i am a little new to openwrt.

#!/usr/bin/sh
/bin/sh /usr/share/libubox/jshn.sh
#while true
#do
#sleep 5
bletool on
bletool discovery_type 1 1
bletool discovery 1 1 0 | awk '{print;exit}'> /tmp/blesniffer.log
bletool end_procedure
adv_data= `awk '{print}' /tmp/blesniffer.log`
date=`date '+%Y%m%d%H%M%S'`
json_init
json_add_string "api" "/user/data"
json_add_object "data"
json_add_string "date" "$date"
json_add_string "advertising data" "$adv_data"
json_close_object
json_close_object
data=`json_dump`
#ubus call mqtt pub "$data"
#rm /tmp/blesniffer.log
@YaoSir
Copy link
Contributor

YaoSir commented Jun 4, 2019

I know what happend to your code.
bletool discovery 1 1 0 | awk '{print;exit}'> /tmp/blesniffer.log
Here, your code means the 'awk ' will write the the first string it recieved to the '/tmp/blesniffer.log' and then exit. After excute the command 'bletool discovery 1 1 0', the first string you get is 'ok'. So, the blesniffer has only one string 'ok'.
The 'awk' here is to filter the message you want, just like device name( the demo), or mac, or some others. If you want get all the messages, you can write like this:
bletool discovery 1 1 0 > /tmp/blesniffer.log sleep 3 bletool end_procedure
Hope it can help you.

@shakilbharucha
Copy link
Author

Thank you YaoSir
For your quick response, i had tried that prior and the file write command keeps executing the file write operations also writes data to file. But the synchronous operation, keep writing data to the file doesn't move ahead to execute the next line, sleep 5 and bletool end_procedure. The code gets stucked while writing the file.
I also tried running that piece of code in background, however, it gives just writes "no response" in the file and code execution generates error as it doesnt find expected data in file.

@YaoSir
Copy link
Contributor

YaoSir commented Jun 5, 2019

I don't know exactly what you mean by "synchronous operation". Would you tell us what you want to do?
Maybe we can give some detail suggestion.
The command "bletool discovery 1 1 0" get the ble module to a state that continuously recieve ble advertising messages nearby. AND IT WILL NOT END BY HIMESELF! You can type "CRTL"+"C" to end it in command line or you can use "killall bletool" to end it in a shell scripts.

@shakilbharucha
Copy link
Author

Hello YaoSir,
This is exactly my problem, in this particular mode, it doesnt end by itself, however to force end it, the shell script doesnt even execute the next line.
So lets say

bletool discovery 1 1 0
echo "Kill ble tool"

The echo never gets executed.
I would try though by setting up scan interval and scan duration command and see if it helps.

@YaoSir
Copy link
Contributor

YaoSir commented Jun 11, 2019

I have test it.
You can use scripts like this:
bletool discovery 1 1 0 killall bletool
Not "echo 'kill bletool' ".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants