{"id":281,"date":"2020-05-26T23:23:01","date_gmt":"2020-05-27T02:23:01","guid":{"rendered":"http:\/\/fabiobrandao.net.br\/blog\/?p=281"},"modified":"2020-05-27T20:34:17","modified_gmt":"2020-05-27T23:34:17","slug":"primeiros-testes-com-eclipse-ponte","status":"publish","type":"post","link":"https:\/\/fabiobrandao.net.br\/blog\/iot\/primeiros-testes-com-eclipse-ponte\/","title":{"rendered":"Primeiros testes com Eclipse Ponte"},"content":{"rendered":"<p>Esta semana comecei a fazer alguns testes com um projeto novo da funda\u00e7\u00e3o <a href=\"http:\/\/eclipse.org\/\">Eclipse<\/a>. Trata-se do <strong>Ponte<\/strong> (<a href=\"https:\/\/www.eclipse.org\/ponte\">https:\/\/www.eclipse.org\/ponte<\/a>), uma implementa\u00e7\u00e3o em <strong>Node.js<\/strong> (<a href=\"http:\/\/nodejs.org\">http:\/\/nodejs.org<\/a>) que permite o envio e recep\u00e7\u00e3o de dados utilizado 3 protocolos diferentes: <strong>MQTT<\/strong>, <strong>HTTP<\/strong> e <strong>CoAP<\/strong>.<\/p>\n<p>Outra caracter\u00edstica importante desta aplica\u00e7\u00e3o \u00e9 a persist\u00eancia dos dados, atualmente com suporte para o <strong>MongoDB<\/strong>, <strong>Redis<\/strong> e <strong>LevelDB<\/strong>. Isso define o Ponte como um broker m\u00e1quina a m\u00e1quina de m\u00faltiplos protocolos para <strong>IoT<\/strong>.<\/p>\n<figure id=\"attachment_286\" aria-describedby=\"caption-attachment-286\" style=\"width: 861px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-286\" src=\"http:\/\/fabiobrandao.net.br\/blog\/wp-content\/uploads\/2020\/05\/ponte-shema.png\" alt=\"Arquitetura Ponte\" width=\"861\" height=\"537\" srcset=\"https:\/\/fabiobrandao.net.br\/blog\/wp-content\/uploads\/2020\/05\/ponte-shema.png 861w, https:\/\/fabiobrandao.net.br\/blog\/wp-content\/uploads\/2020\/05\/ponte-shema-300x187.png 300w, https:\/\/fabiobrandao.net.br\/blog\/wp-content\/uploads\/2020\/05\/ponte-shema-768x479.png 768w\" sizes=\"auto, (max-width: 861px) 100vw, 861px\" \/><figcaption id=\"caption-attachment-286\" class=\"wp-caption-text\">Arquitetura Ponte<\/figcaption><\/figure>\n<p>O procedimento de instala\u00e7\u00e3o e bem simples, s\u00f3 precisei atualizar o Node.js em meu Windows e executar o comando <strong><em>npm install ponte -g<\/em><\/strong>.<\/p>\n<p>Ap\u00f3s a instala\u00e7\u00e3o executei o comando <em>ponte <strong>&#8211;version<\/strong><\/em> para checar a instala\u00e7\u00e3o e a vers\u00e3o. Uma lista dos comandos dispon\u00edveis pode ser obtida com o comando <strong><em>ponte &#8211;help<\/em><\/strong>.<\/p>\n<p><em>-h, &#8211;help output usage information<\/em><br \/>\n<em>-V, &#8211;version output the version number<\/em><br \/>\n<em>-o, &#8211;observe Observe the given resource<\/em><br \/>\n<em>-n, &#8211;no-new-line No new line at the end of the stream<\/em><br \/>\n<em>-p, &#8211;payload &lt;payload&gt; The payload for POST and PUT requests<\/em><br \/>\n<em>-b, &#8211;block2 &lt;option&gt; set the block2 size option<\/em><br \/>\n<em>-q, &#8211;quiet Do not print status codes of received packets<\/em><br \/>\n<em>-c, &#8211;non-confirmable non-confirmable<\/em><br \/>\n<em>-t, &#8211;timeout &lt;seconds&gt; The maximum send time in seconds<\/em><br \/>\n<em>-T, &#8211;show-timing Print request time, handy for simple performance tests<\/em><br \/>\n<em>-O, &#8211;coap-option &lt;key,value&gt; Add COAP-Option to the request (repeatable)<\/em><\/p>\n<p>Para iniciar a aplica\u00e7\u00e3o voc\u00ea pode usar o comando<em> ponte -m 1883<\/em> onde 1883 \u00e9 o n\u00famero da porta. Se quiser uma inicializa\u00e7\u00e3o com log use o comando <strong><em>ponte -v<\/em><\/strong>. Quando voc\u00ea habilita o log (verbose), \u00e9 poss\u00edvel ver em qual porta cada protocolo estar\u00e1 escutando. A configura\u00e7\u00e3o padr\u00e3o \u00e9:<\/p>\n<ul>\n<li>MQTT 1883;<\/li>\n<li>HTTP 3000;<\/li>\n<li>CoAp 5683.<\/li>\n<\/ul>\n<p>Meu primeiro teste foi utilizando um client MQTT (<a href=\"https:\/\/github.com\/francoisvdm\/TT3\">TT3<\/a>) para publicar uma mensagem e obter esta mensagem via HTTP (<a href=\"https:\/\/www.postman.com\/\">Postman<\/a>). Configurei o t\u00f3pico &#8220;test&#8221; para envio das mensagens. Para poder obter a mensagem via HTTP, voc\u00ea deve usar a op\u00e7\u00e3o reter as mensagens em seu client MQTT.<\/p>\n<figure id=\"attachment_285\" aria-describedby=\"caption-attachment-285\" style=\"width: 890px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-285\" src=\"http:\/\/fabiobrandao.net.br\/blog\/wp-content\/uploads\/2020\/05\/ponte-mqtt-send-message.png\" alt=\"Send MQTT menssage \" width=\"890\" height=\"351\" srcset=\"https:\/\/fabiobrandao.net.br\/blog\/wp-content\/uploads\/2020\/05\/ponte-mqtt-send-message.png 890w, https:\/\/fabiobrandao.net.br\/blog\/wp-content\/uploads\/2020\/05\/ponte-mqtt-send-message-300x118.png 300w, https:\/\/fabiobrandao.net.br\/blog\/wp-content\/uploads\/2020\/05\/ponte-mqtt-send-message-768x303.png 768w\" sizes=\"auto, (max-width: 890px) 100vw, 890px\" \/><figcaption id=\"caption-attachment-285\" class=\"wp-caption-text\">Send MQTT menssage<\/figcaption><\/figure>\n<p>J\u00e1 do lado HTTP basta fazer uma requisi\u00e7\u00e3o <strong>GET<\/strong> para <strong><em>http:\/\/localhost:3000\/resources\/test<\/em><\/strong> e obter a \u00faltima mensagem.<\/p>\n<figure id=\"attachment_289\" aria-describedby=\"caption-attachment-289\" style=\"width: 635px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-289\" src=\"http:\/\/fabiobrandao.net.br\/blog\/wp-content\/uploads\/2020\/05\/ponte-http-receive-message.png\" alt=\"Recebendo mensagem HTTP\" width=\"635\" height=\"309\" srcset=\"https:\/\/fabiobrandao.net.br\/blog\/wp-content\/uploads\/2020\/05\/ponte-http-receive-message.png 635w, https:\/\/fabiobrandao.net.br\/blog\/wp-content\/uploads\/2020\/05\/ponte-http-receive-message-300x146.png 300w\" sizes=\"auto, (max-width: 635px) 100vw, 635px\" \/><figcaption id=\"caption-attachment-289\" class=\"wp-caption-text\">Recebendo mensagem HTTP<\/figcaption><\/figure>\n<p>Em seguida, minha tentativa foi fazer o oposto, agora enviando via HTTP e recebendo via MQTT. Para enviar via HTTP basta fazer um requisi\u00e7\u00e3o <strong>PUT<\/strong> para <strong><em>http:\/\/localhost:3000\/resources\/test<\/em><\/strong> e enviar a mensagem desejada. At\u00e9 aqui tudo funcionou muito bem.<\/p>\n<figure id=\"attachment_291\" aria-describedby=\"caption-attachment-291\" style=\"width: 635px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-291\" src=\"http:\/\/fabiobrandao.net.br\/blog\/wp-content\/uploads\/2020\/05\/ponte-http-send-message.png\" alt=\"Enviando mensagem HTTP\" width=\"635\" height=\"309\" srcset=\"https:\/\/fabiobrandao.net.br\/blog\/wp-content\/uploads\/2020\/05\/ponte-http-send-message.png 635w, https:\/\/fabiobrandao.net.br\/blog\/wp-content\/uploads\/2020\/05\/ponte-http-send-message-300x146.png 300w\" sizes=\"auto, (max-width: 635px) 100vw, 635px\" \/><figcaption id=\"caption-attachment-291\" class=\"wp-caption-text\">Enviando mensagem HTTP<\/figcaption><\/figure>\n<p>Agora falta um teste, utilizando o protocolo CoAP. Para isso utilizei o <strong>coap-cli<\/strong> (<a href=\"http:\/\/github.com\/mcollina\/coap-cli\">http:\/\/github.com\/mcollina\/coap-cli<\/a>) disparando o seguinte comando:<\/p>\n<p><em>echo &#8216;Message 1 from CoAP&#8217; | coap put coap:\/\/localhost\/r\/test<\/em><\/p>\n<p>Sensacional, consegui obter a mensagem tanto via MQTT quanto HTTP.<\/p>\n<p>Esta primeira etapa etapa foi conclu\u00edda e a aplica\u00e7\u00e3o Ponte se saiu bem nos testes, atendendo sua proposta.<\/p>\n<p>As configura\u00e7\u00f5es e persist\u00eancia de dados fica para um artigo futuro.<\/p>\n<p>O projeto e mais informa\u00e7\u00f5es voc\u00ea pode obter em\u00a0<a href=\"https:\/\/github.com\/eclipse\/ponte\">https:\/\/github.com\/eclipse\/ponte<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Esta semana comecei a fazer alguns testes com um projeto novo da funda\u00e7\u00e3o Eclipse. Trata-se do Ponte (https:\/\/www.eclipse.org\/ponte), uma implementa\u00e7\u00e3o em Node.js (http:\/\/nodejs.org) que permite o envio e recep\u00e7\u00e3o de&#8230; <\/p>\n","protected":false},"author":1,"featured_media":145,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[24],"tags":[63,60,62,25,23,61],"class_list":["post-281","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-iot","tag-coap","tag-eclipse","tag-http","tag-iot","tag-mqtt","tag-ponte"],"_links":{"self":[{"href":"https:\/\/fabiobrandao.net.br\/blog\/wp-json\/wp\/v2\/posts\/281","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fabiobrandao.net.br\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fabiobrandao.net.br\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fabiobrandao.net.br\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fabiobrandao.net.br\/blog\/wp-json\/wp\/v2\/comments?post=281"}],"version-history":[{"count":13,"href":"https:\/\/fabiobrandao.net.br\/blog\/wp-json\/wp\/v2\/posts\/281\/revisions"}],"predecessor-version":[{"id":298,"href":"https:\/\/fabiobrandao.net.br\/blog\/wp-json\/wp\/v2\/posts\/281\/revisions\/298"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/fabiobrandao.net.br\/blog\/wp-json\/wp\/v2\/media\/145"}],"wp:attachment":[{"href":"https:\/\/fabiobrandao.net.br\/blog\/wp-json\/wp\/v2\/media?parent=281"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fabiobrandao.net.br\/blog\/wp-json\/wp\/v2\/categories?post=281"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fabiobrandao.net.br\/blog\/wp-json\/wp\/v2\/tags?post=281"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}