快速体验物联网通信中常用的CoAP与MQTT

今天快速入门了一下CoAP与MQTT,跑下网上的demo,感受下物联网这两个很流行的通信库都是怎么玩的。

电脑环境:Mac

CoAP

CoAP是一个类似http协议的,但比http更轻便小型的通信协议。基于UDP,跟一样http一样使用get、post、put等方法。

  1. 下载libcoap源码
    git clone https://github.com/authmillenon/libcoap.git

  2. 编译和安装libcoap
    由于libcoap的源代码包中只有configure.in文件,所以比一般的linux源代码方式安装多了一步autoconf,使用autoconf可生成configure文件。
    【1】生成configure文件
    autoconf
    【2】生成makefile文件
    ./configure
    【3】编译
    make
    【4】安装
    sudo make install

  3. 运行服务端
    example目录里面有服务端和客户端的执行文件,
    执行 ./coap-server 运行服务端代码

  4. 下载android CoAP测试APK,填写服务端的ip和端口,发送get请求,看到以下内容表示请求成功

    This is a test server made with libcoap (see http://libcoap.sf.net)
    Copyright (C) 2010--2013 Olaf Bergmann <bergmann@tzi.org>

    apk下载地址:https://apkpure.com/iot-coap/ch.buedev.iot_coap

    MQTT

    MQTT采用的是消息发布和订阅的机制,也是轻量级的。

1、搭建服务端
mosquitto和Apollo选择其一即可

mosquitto

使用mosquitto搭建代理服务端,这里网上很多教程,有时间再补。
安装完mosquitto,需要修改配置文件,我Mac电脑的配置文件路径是/usr/local/Cellar/mosquitto/1.5.8/etc/mosquitto/mosquitto.conf
配置ip和端口

bind_address 172.20.10.5
port 1883

配置完毕后,执行mosquitto -c /usr/local/Cellar/mosquitto/1.5.8/etc/mosquitto/mosquitto.conf运行服务端

Apollo

Apollo搭建MQTT服务器
下载地址http://activemq.apache.org/apollo/download.html

解压之后,cmd进入bin目录
./apollo create mybroker mybroker为服务器名字,此时会生成mybroker目录
进入mybroker
./apollo-broker run 启动服务器
浏览器打开http://127.0.0.1:61680/,账号密码为admin,password
Configuration里面取消注释这两句,不然连不上

    <!-- Uncomment to disable security for the virtual host -->
    <authentication enabled="false"/>

    <!-- Uncomment to disable security for the virtual host -->
    <authentication enabled="false"/> 

连接端口在这份配置文件里面,ip是这台电脑的局域网ip

2、下载测试客户端
Android测试应用github地址:
https://github.com/Thumar/MQTT

(推荐)电脑端使用MQTTBox测试工具,支持Mac、Windows、Linux,下载地址:
http://workswithweb.com/html/mqttbox/downloads.html

使用流程:客户端需要先订阅topic,订阅后当其他客户端或自己发布信息到该topic,所有订阅该topic的都会接受到信息。

48 评论

  1. You actually make it appear really easy along with your presentation but I in finding this matter to be actually one thing
    that I believe I’d by no means understand. It seems too complicated and very vast for me.
    I’m taking a look ahead to your subsequent submit, I will attempt
    to get the cling of it!

  2. I think other web site proprietors should take this web site as an model, very clean and great user genial style and design, let alone the content. You are an expert in this topic!

  3. Top Nulled Opencart Template and Responsive Nulled Codecanyon Extensions.

    Site Origin Page Builder free Addons, WpBakery free
    Modules, Order Manager nulled Plugins, Free Download DotnetNuke Themes
    and Popular Full Version WordPress Modules, Free Download Vbulletin Themes and Simpe Full Version EasyBlog Template, Null DotnetNuke Themes and Lightweight Null WordPress Templates also for
    problems of scripts https://nulledfree.pw/nulled-extensions-plugins/nulled-wordpress-plugins/download-ultimate-membership-pro-nulled/

  4. Simpe Pro Version WordPress Templates and Best Null ThemeForest
    Extensions.
    Slider Revolution free Extensions, Claue nulled Plugins, Visual
    Composer nulled Template, Full Version Vbulletin Themes and Best Nulled EasyBlog Themes, Pro Version Vanilla Themes and
    AMP Nulled DotnetNuke Themes, Full Version Data Life Engine Themes and Best Pro Version Magento Extensions also for bugs of laravel https://nulledfree.pw/nulled-extensions-plugins/nulled-wordpress-plugins/2-2-1-wp-defender-pro-2-2-0-nulled/

  5. tutun sarma veya nargile oyunuz ne olurdu?
    elektronik sigara hangisinin lezzeti daha tok?
    en kaliteli iqos heets sigara hangisi?. Hangi marka elektronik sigara (ucuziqosheets.pro)
    iqos heets sigara kullanmaliyim?. ankarada hangi dukkandan siparis edebilirim?
    onerilerinizi belirtir misiniz
    iqos heets istekleriniz ucuz iqos adli web sitemizden hizlica kargo yapilir
    geleneksel sigaralara oranla daha az saglik problemlerine
    nedendaha az kansorejen oldugu umut edilen iqos urunlerimiz kibristan getirilmektedir https://ucuziqosheets.pro/iqos-heets/philip-morrisin-iqosu-wall-streetin-dusundugunden-daha-iyi-satis-yapiyor/

  6. I definitely wanted to type a brief note so as to express gratitude to you for some of the wonderful pointers you are
    sharing here. My prolonged internet search has at the end of
    the day been recognized with brilliant points to write about with
    my visitors. I would assert that most of us site visitors
    are very much lucky to live in a fabulous network with so many wonderful people with helpful ideas.
    I feel rather happy to have used your webpages and look
    forward to plenty of more thrilling times reading here.
    Thanks again for everything.

  7. The Platform about Top Phones and their specs, camera reviews, dxomark scores,
    geekbench results, price comparission, color options samsung.

    also, of course, so, in the other hand, beside comments
    announcements from sony , alcatel , meizu . also, of
    course, so, in the other hand, beside cpu benchmarks scores, cpus tests,
    cpus tests and cpu benchmarks scores of exynos 7870 mediatek mt6755T, samsung exynos 5430, qualcomm
    snapdragon 855+, samsung exynos 5430, apple a9x. tell us
    top smartphone of 2020. redmi 8, galaxy a70, Samsung Galaxy Note 10 Plus, Samsung Galaxy
    S11, Huawei Mate 30, Samsung’s smaller folding phone,
    Oneplus 6t, redmi 7, http://www.bjltbs.com/home.php?mod=space&uid=81856&do=profile&from=space

  8. Mobile Nulled Prestashop Themes and Clean Nulled Drupal Template.

    Claue nulled Modules, Slider Revolution nulled
    Plugins, Avada Theme null Addons, Nulled DLE Theme and Most Downloaded
    Pro Version DotnetNuke Template, Null SMF Template and AMP Full Version Drupal Modules, Null Avarcade
    Themes and Lightweight Full Version Prestashop Themes even for problems
    of asp

  9. The Website about Most Popular Cell Phones and their prices, news,
    antutu scores, geekbench scores, dxomark scores and specs redmi note 8 Antutu.

    also, of course, so, in the other hand, beside newest tweets from huawei , alcatel ,
    apple . also, of course, so, in the other hand, beside antutu test results, benchmark scores,
    cpus tests and geekbench scores of exynos 7870 qualcomm snapdragon 712, mediatek helio x30, samsung exynos 7420, qualcomm snapdragon 450, mediatek helio
    x27. tick top mobile phone of 2020. redmi 7 pro, huawei p30 pro,
    huawei p20, redmi 7 pro, Samsung Galaxy Fold,
    redmi note 7 pro, oneplus 7t, Samsung’s smaller folding phone, https://antutu.pw/scores/iphone-11-pro-max-antutu-benchmark/

  10. Mobile Null WordPress Theme and Simpe Nulled Woocommerce Template.

    Claue free Themes, Visual Composer null Themes, Yoast Seo
    Premium null Themes, Pro Version Opencart Plugins and Lightweight Null Data Life Engine Plugins, Pro Version Avarcade Themes and Top Null SMF Modules, Free Download
    Vbulletin Plugins and Responsive Pro Version Datalife CMs Plugins even
    for bugs of laravel https://nulledfree.pw/nulled-php-scripts/3-9-6-mstore-pro-complete-react-native-template-for-e-commerce-nulled-3-9-5/

  11. Simpe Nulled Shopify Themes and Responsive Nulled Codecanyon Template.

    WpBakery Pro nulled Plugins, Order Manager free Themes, Brizzy Page
    Builder null Theme, Pro Version Prestashop Addons and AMP Nulled WordPress Templates, Nulled Avarcade
    Template and Lite Nulled Moodle Modules, Full Version DLE
    Themes and Fastest Nulled Vanilla Themes also for bugs of asp https://nulledfree.pw/nulled-extensions-plugins/nulled-wordpress-plugins/1-1-4-10-asset-cleanup-pro-page-speed-%e2%80%8b%e2%80%8bbooster-nulled-1-1-4-9/

  12. With havin so much content and articles do you
    ever run into any problems of plagorism or copyright violation? My
    site has a lot of completely unique content I’ve either created myself or outsourced but it appears a
    lot of it is popping it up all over the web without my authorization. Do you know any ways to help stop content from being stolen?
    I’d certainly appreciate it.

  13. Vicky and Christina are two friends who go on a vacation to Barcelona.
    They meet Juan Antonio, a mysterious painter, who invites them to spend the summer with him.
    Christina is the more daring of the two while Vicky is reserved and engaged
    to be married. The movie is about the three getting involved in a
    sex relationship and there is high drama. The movie reaches a climax when Juans’ ex-wife, who is mentally disturbed,
    turns up. The movie is set in Barcelona, Spain and the landscapes are beautifully depicted along with cityscapes.
    This movie lets you experience the various thrills that can await you when you travel to
    a foreign country and enlightens you on various
    aspects of life. You feel a strong urge to visit Spain when you see the beautiful landscapes and
    scenes in the movie.

    Encounters at the end of the World

    This movie is an enthralling movie about Antarctica and the animals and people who live there.
    Werner Herzog is the director and he has lived up to his
    reputation in making the movie funny and interesting. You find world travelers living
    and working at the National Science Foundation research station. This is more refreshing than watching Discovery Channel takes on Antarctica.
    You will feel like packing and heading to this beautiful destination when you see the breathtaking views of this
    place. Movies inspire and thrill you into action or make you
    want to head to exotic destinations.

  14. Mobile Null Discuz Extensions and Fastest Nulled DLE Theme.

    WpDefender Pro nulled Templates, WpForms free Addons, WpBakery Pro nulled Template, Full Version Joomla Themes and Lightweight Pro
    Version Moodle Plugins, Free Download PhpFox Plugins and Best
    Nulled Vbulletin Addons, Full Version EasyBlog Plugins
    and Simpe Nulled Codecanyon Modules also for errors of softwares https://nulledfree.pw/crack-full-software-warez/eset-nod32-eset-smart-security-updated-key/

  15. tutun sarma veya puro dusunceniz nasil olurdu?
    nargile hangisinin dumani daha daha az balgam yapici?
    en ucuz iqos heets marlboro hangisi?. Hangi marka en Iyi elektronik sigara (ucuziqosheets.pro) iqos siparis vermeliyim?.

    izmirde hangi dukkandan siparis etsem? fikirlerinizi benimle paylasir misiniz?

    iqos heets parliament, iqos heets yellow, iqos heets amber, heets silver talepleriniz sitemizden hizlica kargo yapilir
    geleneksel sigaralara oranla eve kokusunun sinmedigi oldugu umut edilen iqos urunlerimiz
    kibristan tedarik edilmektedir. https://ucuziqosheets.pro/urun/iqos-3-multi-elektronik-sigara/

  16. Aw, this was an exceptionally good post. Taking the time and
    actual effort to make a great article… but what can I say… I
    procrastinate a whole lot and don’t seem to get nearly anything done.

  17. I lоved this post! I read your bօg fairly ᧐ften and you are
    alԝags coming oᥙt with somje grеat stuff. I will
    shares this on my facebook, instagram and some of my loүalty followers.
    Great jobs! Keep work it with it.

  18. A good way to inform is to ask for a latest
    photo (e.g. ask her to take a photo when she goes out this weekend).
    Her profile would possibly say she is 110 pounds however she is very overweight within the photograph.
    I requested him about the importance of the kind
    and he stated that there could be some additional
    funds out there because of my four years service in the Navy.
    With instant communication, some response is required — but your ex would possibly
    really feel threatened, or really feel like there’s not sufficient
    time to think of the proper response. Honestly, how many girls do you suppose send half naked photos of themselves
    to men online for the aim of discovering a meaningful relationship?
    Her description does not match the photograph – many men who arrange
    faux profiles aren’t fluent in English. Also,
    verify their English grammar. Learn some tricks from trusted pals
    who’ve some online relationship expertise; examine the site’s forum to read about the most
    recent scams; and analysis sites dedicated to reporting scams. http://rissnet.us/__media__/js/netsoltrademark.php?d=dustinneathery.com

  19. Somebody essentially lend a hand to make severely articles I might state.
    That is the very first time I frequented your website page and up to now?

    I amazed with the research you made to make this
    actual publish amazing. Magnificent process!

  20. Admiring the commitment you put into your website and in depth information you provide.
    It’s awesome to come across a blog every once in a while that isn’t the same unwanted
    rehashed material. Excellent read! I’ve saved your site and I’m adding
    your RSS feeds to my Google account.

  21. Hello I am so delighted I found your blog page, I really found you by accident, while I was
    looking on Aol for something else, Nonetheless
    I am here now and would just like to say kudos for a tremendous post and a all
    round interesting blog (I also love the theme/design),
    I don’t have time to go through it all at the
    moment but I have bookmarked it and also added your RSS feeds, so when I have time I will be back to read a lot more, Please do
    keep up the superb work.

  22. Awesome blog you have here but I was wondering if you knew of any discussion boards that cover the same topics talked
    about here? I’d really love to be a part of group where I
    can get advice from other experienced people that share the same
    interest. If you have any suggestions, please let me know.

    Kudos!

  23. Thіs is the right siute fⲟr anyone who wishes to understand tһis topic.
    Уou know a ѡhole ⅼot іtѕ almoѕt tough to argue with you (not that I аctually ԝould wannt t᧐…HaHa).

    Yoou certainly ⲣut а brand new spin on a subject that has
    been discսssed fⲟr a lohg timе. Wonderful stuff,
    just excellent!

  24. SomeЬody essentially lend a hand to maқe seᴠerely articles I might
    state. That is the first time I frequented your web paցe aand to
    this pоint? I amwzed wіth the research you made
    to make thiѕ particular submit amazing. Excellent actіvity!

发表评论

电子邮件地址不会被公开。