# Alarming Loss of Comms to Devices

**URL:** <https://forum.inductiveautomation.com/t/alarming-loss-of-comms-to-devices/52858>\
**Category:** Ignition\
**Created:** [November 9, 2021, 4:11am UTC](https://forum.inductiveautomation.com/t/alarming-loss-of-comms-to-devices/52858 "2021-11-09T04:11:21Z")\
**Posts on this page:** 1\
**Showing post:** 2

<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:** [November 9, 2021, 10:37am UTC](https://forum.inductiveautomation.com/t/alarming-loss-of-comms-to-devices/52858/2 "2021-11-09T10:37:09Z")

</div>

Welcome, Craig!

You will find with Ignition there is no ‘one-way’ of doing things, there are multiple ways this can be done.

This is how I do it, note the version is 7.9 so scripts will need slight updates for best performance on 8.1.x

You seem to be concerned with loss to a single device, the following is for an overview of all devices but it might give you some ideas.

I have a tag that counts the total number of connected devices:

```auto
import system
		
cDS = system.dataset.toPyDataSet(deviceDataset)

c=0
for r in cDS:
	if r['State']=="Connected":
		c = c + 1

system.tag.write("Diagnostics/Devices_Connected", c)

```

I have an alarm set on this tag saying if below X count and for Y duration then send an email out.

Further to that I have a power table with a ‘refresh’ button with the following script:

```auto
deviceDataset = system.device.listDevices()
 
# Assign the deviceDataset to a Power Table. This example assumes
# the Power Table is in the same container as the component that called this script
event.source.parent.getComponent('Power Table').data = deviceDataset

```

This allows you to see at a glance what devices are connected/connecting/disconnected/disabled and the driver type, easier than the gateway status page as it is constantly refreshing.

Further to that I have a periodic script that pings each device and records the status to a DB, this then lets me see if there are drops in the diagnostic count which sites were not responding at that time historically;

```auto
def ping(address,timeout=2000):
	global pingStat
	from java.net import InetAddress
	ip = InetAddress.getByName(address)
	if ip.isReachable(timeout) == True:
		pingStat = 1
	elif ip.isReachable(timeout) == False:
		pingStat = 0

def dev_ping():
	dlist = system.device.listDevices()
	for row in range(dlist.getRowCount()):
		# Check if device uses ModbusTCP driver and device is enabled
		if dlist.getValueAt(row,3) == "ModbusTcp" and dlist.getValueAt(row,1) == 1:
			# Get device host name.
			devSite = dlist.getValueAt(row,0)
			print devSite
			devIP = system.device.getDeviceHostname(dlist.getValueAt(row,0))
			print devIP
			ping(devIP)
			if pingStat == 1:
				print "Dev ok"
				system.db.runSFPrepUpdate("insert into ign.dev_stat (dev_site, dev_ip, dev_state) values (?,?,?)",[devSite, devIP, pingStat],datasources=["MySQL"])
			
			elif pingStat == 0:
				print "no conn"
				system.db.runSFPrepUpdate("insert into ign.dev_stat (dev_site, dev_ip, dev_state) values (?,?,?)",[devSite, devIP, pingStat],datasources=["MySQL"])
				
dev_ping()

```

As usual, YMMV.

---

_[View the full topic](https://forum.inductiveautomation.com/t/alarming-loss-of-comms-to-devices/52858)._
