TCP Client via Python

I am trying to setup some simple data collection/streams. I want to explore MQTT in the future, but right now need a proof of concept before I can buy more modules.

I currently have a RPi setup with some sensors. My plan was to setup a TCP Socket server in Python on the RPi and setup Ignition to connect to the device and gather the stream of data. My basic setup on the RPi is a socketserver running a TCPServer.

Whenever a client connects, the data is sent every second. Just testing with random data right now, but future will only send the changed data based upon the actual sensor inputs.

        self.data = str(random.random()) + "::" + str(random.random()) + "::" + str(random.random()) + ";;"
        print "{}: Write {}".format(self.client_address[0], self.data)
        self.request.sendall(self.data)
        time.sleep(1)

I setup a device in Ignition and am able to see the data in OPC! Good so far. However, I am getting the below error every second in the console!! :frowning: What is going on?

9:35:57 AM TCPConnection[9999] Connection lost. java.io.IOException: End of stream reached.

Also, is the above a good approach, an other suggestions? I though also about setting up OPCUA on the RPi, but like to be able to keep it simpler with just raw TCP.

You might want to have a look at the code in this post. It’s UDP, not TCP but it should be pretty similar.

If you goal is MQTT , then why not setup a ActiveMQ broker and have the Pi talk MQTT?
No sense in parsing raw streams is there?

I am fine with the MQTT on the client side and getting a broker setup, but I am unsure how to link Ignition to the MQTT broker. That is really the only reason for going plain TCP messages.

Are there any free/low cost MQTT drivers for Ignition out there? I saw the Cirrus Link demo, but have not reached out to them yet to get an idea of cost.

I am fairly new to Ignition and still unfamiliar with the Python runspace, but wouldn’t it be as simple as finding the right MQTT Python library and pointing it at the broker?

It might be tough to find a MQTT client library that works with Python 2.5 and MQTT 3.1.1.

pypi.python.org/pypi/paho-mqtt

@agsense has started some MQTT work: inductiveautomation.com/forum/v … 41&t=13812

/c

[quote=“cmisztur2”]I am fairly new to Ignition and still unfamiliar with the Python runspace, but wouldn’t it be as simple as finding the right MQTT Python library and pointing it at the broker?

It might be tough to find a MQTT client library that works with Python 2.5 and MQTT 3.1.1.
[/quote]

There’s that, but Ignition uses Jython, so if you’re wanting to use a 3rd party library, be sure there are no dependencies on any C libraries (Like numpy, for example)

ahhh ok…

So would this be correct?

  1. create a Java module
  2. wrap eclipse.org/paho/clients/java/ in the module
  3. make module visible to Ignition (how?)
  4. use new Java module to perform MQTT (memory management?)

/c

[quote=“cmisztur2”]So would this be correct?[/quote]Yes. Ignition has a Module SDK for this type of development, either the ant-based version for v7.7.x or the maven-based version for 7.8+.
{There’s some cross-over, actually. IA has been using maven internally for a while now. I’ve been using the ant system with some tweaks for v7.8 without issue.}