• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

Module 7- Unit 3 -Publishing more topics – adding another sensor

Q&A Forum › Module 7- Unit 3 -Publishing more topics – adding another sensor
0 Vote Up Vote Down
Geert Esselens asked 7 years ago

The whole course as been very nice! Thank you for this.

I am playing with the mqqt protocol. Completed this course with a light measurement sensor and it worked fine with a graph on the portal from the node-red.

Now I want to add a distance sensor and include it in the webportal. The sensor works fine in the serial monitor but If I just copy the publish code and chance the topic I get the error: “redeclaration of uint16_t packetIdPub2?

 

So essentially I have :

uint16_t packetIdPub2 = mqttClient.publish(“SLITTER/light”, 2, true, LightString.c_str()); //which works fine

uint16_t packetIdPub2 = mqttClient.publish(“SLITTER/distance”, 2, true, DistanceString.c_str());//which is a redeclaration?

I do not fully understand the syntax of this publishing?

All help is welcome,

Geert

ps: I am not using a pure ESP32 but playing with the M5GO (fire) but absolutely no issue during the full course.

 

 

3 Answers
0 Vote Up Vote Down
Rui Santos Staff answered 7 years ago

Hi Geert, you need to use something like this (create a new unit16_t variable):

uint16_t packetIdPub2 = mqttClient.publish("SLITTER/light", 2, true, LightString.c_str()); //which works fine
uint16_t packetIdPub3 = mqttClient.publish("SLITTER/distance", 2, true, DistanceString.c_str());

Parameters:

  1. Topic name
  2. Quality of service
  3. Retain message (yes=true)
  4. Message

Thanks for letting me know! Yes, all ESP32 boards should be compatible with the course if you always double-check the pin assignment!

0 Vote Up Vote Down
Geert Esselens answered 7 years ago

Perfect, that works golden.
Now the sensors are nicely available. 
At this moment they are connected to different ESP32’s and publish correctly to the server.
 
Regards
Geert

0 Vote Up Vote Down
Rui Santos Staff answered 7 years ago

I’m glad it worked! You can simply create more uint16_t packetIdPub3, uint16_t packetIdPub4 and so on for the next topics that you want to publish.
Regards,
Rui

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025
  • [eBook Updated] Learn ESP32 with Arduino IDE eBook – Version 3.2 April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.