# Gateway Event Timer sendMessage not work

**URL:** <https://forum.inductiveautomation.com/t/gateway-event-timer-sendmessage-not-work/71946>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [April 2, 2023, 12:55pm UTC](https://forum.inductiveautomation.com/t/gateway-event-timer-sendmessage-not-work/71946 "2023-04-02T12:55:36Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![471421143](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/471421143/32/38211_2.png) [@471421143](https://forum.inductiveautomation.com/u/471421143)\
**Post date:** [April 2, 2023, 12:55pm UTC](https://forum.inductiveautomation.com/t/gateway-event-timer-sendmessage-not-work/71946/1 "2023-04-02T12:55:36Z")

</div>

![1](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/1/a17fee4e7f5b2be214186b4c95b24207f16d08b5.png)  
 ![2](https://us1.discourse-cdn.com/inductiveautomation/original/3X/d/f/df66f1e3a9a87a3a3f1b17b3f34ab75abf9e73cc.png)

我通过button onclick运行system.perspective.sendMessage("mapRefresh",payload = {}, scope = "session") 是成功(is ok)的.

I want Periodic refresh sendMessage刷新数据, 但是在Gateway Event Timer 中运行代码则不成效(inoperative).

不知道是什么原因, 请帮助我一下. 谢谢!

---

<div class="post-metadata">

**Author:** ![Matrix\_Engineering](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/matrix_engineering/32/19781_2.png) [@Matrix\_Engineering](https://forum.inductiveautomation.com/u/Matrix_Engineering)\
**Post date:** [April 2, 2023, 1:03pm UTC](https://forum.inductiveautomation.com/t/gateway-event-timer-sendmessage-not-work/71946/2 "2023-04-02T13:03:14Z")

</div>

Please post your full code as pre-formatted text.

I suspect one reason your 2nd image code isn't working is because it needs indented one tab. An onClick Mouse Event on a button is a function so at the top there will be:

```auto
def():
   #put your code here

```

where you have done:

```auto
def():
#your code is here

```

---

<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:** [April 2, 2023, 1:03pm UTC](https://forum.inductiveautomation.com/t/gateway-event-timer-sendmessage-not-work/71946/3 "2023-04-02T13:03:20Z")

</div>

You can't use `system.perspective.sendMessage()` outside of Perspective scripts. Gateway events are outside of Perspective. You must use `system.util.sendMessage(...., scope='S')` to deliver to a perspective session message handler, which can then relay with `system.perspective.sendMessage()` to the actual perspective scope you wish to target (if not session).

See this discussion:

> [@Set/Configure tag binding with script in Perspective](https://forum.inductiveautomation.com/t/set-configure-tag-binding-with-script-in-perspective/68906/13):
>
> So, to get this to work I had to make a handler in the project's "Session Events" to receive from system.util.sendMessage(..., scope='S'). It then just calls system.perspective.sendMessage(..., scope='session') with the same payload. The component can receive this latter broadcast. This is a nuance that should be put in the documentation. (That messages broadcast to Perspective via system.util.sendMessage(..., scope='S') can only be received in "Session Events".)

---

<div class="post-metadata">

**Author:** ![471421143](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/471421143/32/38211_2.png) [@471421143](https://forum.inductiveautomation.com/u/471421143)\
**Post date:** [April 2, 2023, 2:09pm UTC](https://forum.inductiveautomation.com/t/gateway-event-timer-sendmessage-not-work/71946/4 "2023-04-02T14:09:06Z")

</div>

> [@Matrix\_Engineering](#):
>
> indented one tab

谢谢您的回复, 我经过测试不是由于缩进的原因导致的.

---

<div class="post-metadata">

**Author:** ![471421143](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/471421143/32/38211_2.png) [@471421143](https://forum.inductiveautomation.com/u/471421143)\
**Post date:** [April 2, 2023, 2:17pm UTC](https://forum.inductiveautomation.com/t/gateway-event-timer-sendmessage-not-work/71946/5 "2023-04-02T14:17:15Z")

</div>

谢谢您的帮助, 按照您的提示, 我的问题已经解决了, sendMessage可以正常工作了. 我的解决步骤如下:

1. Gateway Event --\>timer 中sendMessage
2. Getway Session Event---\>Message中 sendMessage.
3. Vew 中Edit Message Handle接收Recive Message并且执行.

 ![3](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/b/2bca9ef114083a9e8d92d9b065e56ba053587e54.png)  
 ![4](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/a/fad9994bd0dff029a6b02b97618afc5e1d2530d2.png)  
 ![5](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/2/524b296ad6930130cbe51337d4ae92da59156c7b.png)

---

<div class="post-metadata">

**Author:** ![Matrix\_Engineering](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/matrix_engineering/32/19781_2.png) [@Matrix\_Engineering](https://forum.inductiveautomation.com/u/Matrix_Engineering)\
**Post date:** [April 2, 2023, 2:29pm UTC](https://forum.inductiveautomation.com/t/gateway-event-timer-sendmessage-not-work/71946/6 "2023-04-02T14:29:45Z")

</div>

You've put a function in a function. Your def getHostInfo needs indented after def onMessageReceived
