# MQTT Engine gateway event script when message received

**URL:** <https://forum.inductiveautomation.com/t/mqtt-engine-gateway-event-script-when-message-received/66355>\
**Category:** Ignition\
**Tags:** ignition81, scripting\
**Created:** [November 10, 2022, 3:00pm UTC](https://forum.inductiveautomation.com/t/mqtt-engine-gateway-event-script-when-message-received/66355 "2022-11-10T15:00:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![flavien](https://avatars.discourse-cdn.com/v4/letter/f/f475e1/32.png) [@flavien](https://forum.inductiveautomation.com/u/flavien)\
**Post date:** [November 10, 2022, 3:00pm UTC](https://forum.inductiveautomation.com/t/mqtt-engine-gateway-event-script-when-message-received/66355/1 "2022-11-10T15:00:04Z")

</div>

Hi,

I have a project with MQTT messages sent by Automatons.  
With a python script, I would like to INSERT data in my DB when a MQTT message is received.  
Is it possible ?

Thanks

---

<div class="post-metadata">

**Author:** ![zacht](https://avatars.discourse-cdn.com/v4/letter/z/ea5d25/32.png) [@zacht](https://forum.inductiveautomation.com/u/zacht)\
**Post date:** [November 10, 2022, 3:14pm UTC](https://forum.inductiveautomation.com/t/mqtt-engine-gateway-event-script-when-message-received/66355/2 "2022-11-10T15:14:24Z")

</div>

It's definitely possible. You'll probably use either [system.db.runPrepUpdate](https://docs.inductiveautomation.com/display/DOC81/system.db.runPrepUpdate) or [system.db.runNamedQuery](https://docs.inductiveautomation.com/display/DOC81/system.db.runNamedQuery) in your script.

I'm not super familiar with MQTT in Ignition, but I'd guess you'd put the script on a [Gateway Tag Change Event](https://docs.inductiveautomation.com/display/DOC81/Gateway+Event+Scripts#GatewayEventScripts-TagChangeScripts).

---

<div class="post-metadata">

**Author:** ![flavien](https://avatars.discourse-cdn.com/v4/letter/f/f475e1/32.png) [@flavien](https://forum.inductiveautomation.com/u/flavien)\
**Post date:** [November 24, 2022, 9:24am UTC](https://forum.inductiveautomation.com/t/mqtt-engine-gateway-event-script-when-message-received/66355/3 "2022-11-24T09:24:10Z")

</div>

With Gateway Tag Change problem is you can specify a tag in your MQTT Engine provider.  
I would like to insert a new value when coming in my MQTT Engine.

---

<div class="post-metadata">

**Author:** ![flavien](https://avatars.discourse-cdn.com/v4/letter/f/f475e1/32.png) [@flavien](https://forum.inductiveautomation.com/u/flavien)\
**Post date:** [December 16, 2022, 2:47pm UTC](https://forum.inductiveautomation.com/t/mqtt-engine-gateway-event-script-when-message-received/66355/4 "2022-12-16T14:47:30Z")

</div>

> [@zacht](#):
>
> I'm not super familiar with MQTT in Ignition, but I'd guess you'd put the script on a [Gateway Tag Change Event](https://docs.inductiveautomation.com/display/DOC81/Gateway+Event+Scripts#GatewayEventScripts-TagChangeScripts).

But You have to list manually all the MQTT Engine tags.  
Is it possible to write a folder tag path ? I would like to use gateway event script if any tag in the folder has changed.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [December 16, 2022, 2:51pm UTC](https://forum.inductiveautomation.com/t/mqtt-engine-gateway-event-script-when-message-received/66355/5 "2022-12-16T14:51:42Z")

</div>

Gateway tag change events allow a wildcard in the last element of a tagpath in their list.
