Transmitting data to MQTT Broker

Hi, I'm currently trying to send real time analog sensor data to hivemq broker using nrf9160 DK, is it possible to provide source code for this kind of project? I've attached my current code below as well. Thanks

mqtt_simple_sensor.zip

Parents Reply
  • I see you have this line in adc_sample_event().

    data_publish(&client, MQTT_QOS_1_AT_LEAST_ONCE, "test!", 14); 

    You should check the return code of the function, see the snippet below. (and also 14 is not the correct length of the string you are sending)

    Snippet:

    		int ret;
    
    		ret = data_publish(&client,
    				   MQTT_QOS_1_AT_LEAST_ONCE,
    				   your_data,
    				   length_of_your_data);
    		if (ret) {
    			LOG_ERR("Publish failed: %d", ret);
    		}

Children
Related