EMQ X - EmqxBroker CoAP protocol data access test and questions

Don't say anything. Let's take a picture first. Wait... There's also a snapshot;


Let's see how we use CoAP protocol to connect EMQX;

1, Start the coap plug-in and use the code test;

1. Open the emqx COAP plug-in; you can directly click the enable button on the dashboard; (recommended by Win environment)

You can use the command to turn on. / emqx in PowerShell_ ctl plugins load emqx_ COAP (recommended for Linux)

2. At this time, emqx can accept the CoAP protocol data in the specified request format. Please refer to: https://github.com/emqx/emqx-coap

3. java connects to emqx COAP, because only PUT requests can be used. The annotated part of the code is the other two examples of sending COAP PUT requests, which are available after testing;

package com.daopin.project.CoapClient;

 * @Description: TODO(Here is a sentence to describe the function of this class.)
 * @Author daopinz
 * @Date 2020/6/9 14:04
import com.daopin.project.mqtt.PubMsg;
import org.eclipse.californium.core.CoapClient;
import org.eclipse.californium.core.CoapResponse;
import org.eclipse.californium.core.Utils;
import org.eclipse.californium.core.coap.Request;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.net.URI;
import java.util.Date;

import static org.eclipse.californium.core.coap.MediaTypeRegistry.*;

public class CoAPSender {
    private static final Logger logger = LoggerFactory.getLogger(CoAPSender.class);
    public static void main(String[] args) throws Exception {
        //Create a resource request resource. Note that the default port is 5683
        URI uri = new URI("coap://");
        CoapClient client = new CoapClient(uri);
        while (true) {
            String payload = "hello, " + new Date().toString();
            //Set the content of PUT and the type of content TEXT_PLAIN
            //CoapResponse response = client.put(payload, TEXT_PLAIN);
            //Set the content of PUT and the type of content APPLICATION_OCTET_STREAM
            //CoapResponse response = client.put(payload, APPLICATION_OCTET_STREAM);
            Request request = Request.newPut();
            request.setPayload("AAAA0000 "+new Date().toString());
            CoapResponse response = client.advanced(request);


4. Operation code and results;

Our sub end also received subscription data;

The grab bag has been posted on the front. You can refer to it.

2, Summary:

1. Normal CoAP protocol request data should be registered by POST request, followed by a series of GET requests, etc... I don't know if I want to modify the emqx plug-in or how. I don't have a clue

    2. The normal CoAP protocol request data should be carried by payload in the NON/CON message reported by the device after GET subscribing to the device resources, but the emqx CoAP plug-in needs to carry payload in the PUT request, and the subscriber can GET this part of the data, which is actually not compatible with the Huawei Hisilicon chip used in the current domestic IOT market, so I don't know whether it is correct or not Please have experience in this area, do not hesitate to comment!

Tags: Eclipse Java snapshot Linux

Posted on Wed, 10 Jun 2020 02:26:39 -0400 by olm475