Question: What I'm trying to do is to get the REST API to be able to publish to my Mosquitto MQTT Broker (which is also hosted on my Pi on Port 1883) via IFTTT Webhook.
Context
I've built a webapp using ASP.NET Core and it is being hosted on my Raspberry Pi 3 B+ using NGINX. Likewise, I've also made a RESTFUL API using ASP.NET Core. As for the REST API, I can either publish it to Microsoft Azure / Host it on my Pi as well, whichever is better in the solution given.
What I've tried
I've had a successful attempt using Home Assistant's REST API /api/service/mqtt/publish
but to no avail when setting up my own. I'm pretty sure I'm missing something in my ASP.NET Core REST API configuration. I did it just as how I would do any HttpPost thinking it would work.
Code
[Route("api/broker")]
[ApiController]
public class BrokerController : ControllerBase
{
#region HTTPGET
// HTTP GET: /api/broker
[HttpGet]
public IEnumerable<Broker> Get()
{
List<Broker> dbList = DBUtl.GetList<Broker>("SELECT * FROM Broker");
return dbList;
}
}
Things I've attempted:
- Butler-mqtt-master.
- Got it working and it says "Rest Server Listening on http://[::]:8081" But I've no idea what exactly does that mean. My API is available on a azure api link.
- mqtt2rest-master
- Outdated (i think?)
Successful Workaround (but not very reliable / fully functional):
- Node-RED
- By using a
inject node
to constantly poll ahttp request node
at a fixed interval of 4 seconds together with afunction node
and finally pushing the object obtained (with mqtt payload in JSON) to themqtt node
, I am able to get bridge from HTTP RESTapi to MQTT Broker. But this method has lots of loopholes and isn't efficient. If possible I want mine to be working in the same as as how home assistant works.
Link: https://developers.home-assistant.io/docs/en/external_api_rest.html
E.G: Sending a POST request to https:///api/services/mqtt/publish? will send my POST request to the MQTT Broker (which I have no idea how that works)