• 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

How to send data to a REST API from Mosquitto

Q&A Forum › Category: Home Automation › How to send data to a REST API from Mosquitto
0 Vote Up Vote Down
Teodor Birca asked 7 years ago

Hello, 
getting a really good answer at my previous question on this forum makes me to ask another question that i’m researching latelly. So my plan is to have a Raspberry PI with MQTT Mosquitto installed that will grab sensors data from the house. Can you point me to a library or code snippet or what’s the standard way of grabbing the mqqt messages and post them to a Rest API in cloud after please?
 
thanks
teodor

Question Tags: api, cloud, mosquitto, MQTT, rest
4 Answers
0 Vote Up Vote Down
Rui Santos Staff answered 7 years ago

Hello Teodor, I’m gad you found the other answer helpful!
When you say “Rest API”, you basically want to make an HTTP POST or GET request to a web service, right?

0 Vote Up Vote Down
Teodor Birca answered 7 years ago

yes exactly .. i’m just starting with MQTT and i have a custom API on the cloud that accept GET, POST,PUT, DELETE so i’m not sure after the PI gets MQTT message what would be the best way to post it for example to an endpoint. Right now my sensors send post requests directly to cloud but i think is better if i use the PI that accepts MQTT and from there the PI sends the posts. thanks

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

I don’t have any good tutorials on that subject and I should definitely write something about that… I also don’t know any library that could be an abstraction layer to make HTTP requests to APIs easily.

Basically, if you receive the messages via MQTT, you can make an HTTP GET or POST request using the ESP32.

As I said, I don’t have any good examples, but as I show in that project, you make an HTTP request to IFTTT: https://randomnerdtutorials.com/esp8266-wi-fi-button-diy-amazon-dash-button-clone/

You could merge one of the MQTT examples with that HTTP request example to do what you’re looking for. Something like this makes an HTTP GET request:

client.print(String("GET ") + resource + 
" HTTP/1.1\r\n" +
"Host: " + server + "\r\n" + 
"Connection: close\r\n\r\n");

I also recommend that if you’re using Node-RED, you could handle the HTTP request directly on Node-RED.

0 Vote Up Vote Down
Teodor Birca answered 7 years ago

thanks Rui .. i’ll give it a go these days when i have some free time and let you know,
 
regards
Teodor

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

  • [eBook Updated] Learn Raspberry Pi Pico/Pico W with MicroPython eBook – Version 1.2 May 26, 2025
  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition 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.