如何在Linux x86上使用C对蓝牙LE设备进行编程?

如何在Linux x86上使用C对蓝牙LE设备进行编程?,第1张

概述我有一个蓝牙设备,我可以在 linux上使用gatttool控制.我想开发自己的c程序,可以向它发送命令. 我以前做了蓝牙编程,它相对简单,类似于网络编程,但这一次,它是一个蓝牙低功耗设备,并遵循原则here导致主机关闭消息,当我可以清楚地连接/断开它使用gatttool. 我该如何创建这个程序?我知道我应该使用bluez库,但我不知道从哪里开始使用低能耗设备. int main(int argc 我有一个蓝牙设备,我可以在 linux上使用gatttool控制.我想开发自己的c程序,可以向它发送命令.

我以前做了蓝牙编程,它相对简单,类似于网络编程,但这一次,它是一个蓝牙低功耗设备,并遵循原则here导致主机关闭消息,当我可以清楚地连接/断开它使用gatttool.

我该如何创建这个程序?我知道我应该使用bluez库,但我不知道从哪里开始使用低能耗设备.

int main(int argc,char **argv){   struct sockaddr_rc addr = { 0 };   int s,status;   char dest[18] = "B4:99:4C:5C:EE:49";   char buf[2048];   pthread_t rthread;   setbuf(stdout,NulL);    // allocate a socket   s = socket(AF_BLUetoOTH,SOCK_STREAM,BTPROTO_RFCOMM);   // set the connection parameters (who to connect to)   addr.rc_family = AF_BLUetoOTH;   addr.rc_channel = (uint8_t) 1;   str2ba( dest,&addr.rc_bdaddr );   // connect to server   status = connect(s,(struct sockaddr *)&addr,sizeof(addr));   if( status < 0 ){      perror("Error connecting to host\n");      exit(1);   }   while(fgets(buf,sizeof(buf),stdin) != NulL){      status = send(s,buf,0);      if(status < 0){         printf("Error sending.\n");     exit(1);      }   }   close(s);   return;
解决方法 你的程序是经典的蓝牙,为了支持我的声明,我会说在任何经典的蓝牙设备上你的代码工作都可以正常工作

为了得到教团我建议去这个link.sudo ./st会扫描附近的ble divices

https://github.com/carsonmcdonald/bluez-experiments

总结

以上是内存溢出为你收集整理的如何在Linux x86上使用C对蓝牙LE设备进行编程?全部内容,希望文章能够帮你解决如何在Linux x86上使用C对蓝牙LE设备进行编程?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/1050042.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-25
下一篇 2022-05-25

发表评论

登录后才能评论

评论列表(0条)

保存