Industry 4.0 Demo Application

Industry 4.0 Demo Application

Inductive Automation Ignition Edge has been out in the marketplace for a while now. It's an offering of their Ignition platform as an edge-of-network resource. The licensing model offers a stripped down version of Ignition for edge of network HMI applications for about $1000. Consumers can add on MQTT and Store and Forward–to integrate the edge of network gateway with a central enterprise gateway–for a few hundred dollars more. When this was announced back in 2017 it motivated me to put together a quick demo of Ignition using the Cirrus Link MQTT modules, a Raspberry Pi, and ESP8266 Arduino and Kepserver IOT Gateway. I am re-sharing the content today in 2020 because many of our YouTube and LinkedIn followers have asked for an Industry 4.0 application and so I wanted to repost the video and accompanying blog post.The goal here is to help interested developers and end users quickly put together an MQTT Ignition environment to develop in… the process is easy, painless and a lot of fun.

This post is a companion to a comprehensive video we released on our YouTube Channel that you can watch right here on LinkedIn

Watch the video above and use the step-by-step guide below as you follow along.

No alt text provided for this image


Demo Architecture with Raspberry Pi as Broker

Steps:

  1. Install Mosquitto on Raspberry Pi - Pi will be our broker in this example
  2. Install MQTT Spy on Windows - MQTT Spy will be a publisher and subscriber
  3. Setup ESP8266 Arduino - Arduino will read an LM35 temperature sensor and publish two topics:
  • Intellic/Pyramid/Temp
  • outTopic
  1. Install and Setup the Cirrus Link MQTT Modules in Ignition
  2. Install and Setup Kepserver IOT Gateway
  3. Build a test window and play around
Raspberry Pi3, Adafruit Feather HUZZAH ESP8266 with LM35 Temperature Sensor


Step 1. Install Mosquitto on Raspberry Pi

The best instructions I found for installing Mosquitto were here.

  1. Install Mosquitto
  2. Stop the server
  3. Update Mosquitto.conf
  4. Restart server
  5. Open a new terminal and subscribe to a topic - mosquitto_sub -d -t hello/world
  6. Open another terminal and publish to the topic - mosquitto_pub -d -t hello/world -m ‘Test’
  7. Revel in your glory… you just set up a Raspberry Pi3 as an MQTT Broker, subscribed to and published to a topic!
Mosquitto sub
No alt text provided for this image



Step 2. Install MQTT-Spy on Windows

Documentation for MQTT-Spy are here. MQTT-Spy will be used to publish and subscribe to topics from one of our servers. Essentially, we use it in this demo as another agent to show the versatility of MQTT-Spy.

  1. Download MQTT-Spy
  2. Run the jar
  3. Setup a connection with the broker (in our case, 192.168.0.33:1883)
  4. Use hashtag to subscribe to all topics
  5. Revel in your glory… you just set up MQTT-Spy to talk to your broker!
No alt text provided for this image
No alt text provided for this image


Step 3. Setup the ESP8266 Arduino with LM35 Temperature Sensor

Documentation on the ESP8266 can be found here.

  1. Wire up the LM35 to A0 (ADC) analog in
  2. Open up the Arduino IDE and use the code below (add in your SSID and Password and your broker IP address).
/*
 Basic ESP8266 MQTT example

 This sketch demonstrates the capabilities of the pubsub library in combination
 with the ESP8266 board/library.

 It connects to an MQTT server then:
  - publishes "hello world" to the topic "outTopic" every two seconds
  - subscribes to the topic "inTopic", printing out any messages
    it receives. NB - it assumes the received payloads are strings not binary
  - If the first character of the topic "inTopic" is an 1, switch ON the ESP Led,
    else switch it off

 It will reconnect to the server if the connection is lost using a blocking
 reconnect function. See the 'mqtt_reconnect_nonblocking' example for how to
 achieve the same result without blocking the main loop.

 To install the ESP8266 board, (using Arduino 1.6.4+):
  - Add the following 3rd party board manager under "File -> Preferences -> Additional Boards Manager URLs":
       https://arduino.esp8266.com/stable/package_esp8266com_index.json
  - Open the "Tools -> Board -> Board Manager" and click install for the ESP8266"
  - Select your ESP8266 in "Tools -> Board"

*/

#include <ESP8266WiFi.h>
#include <PubSubClient.h>

// Update these with values suitable for your network.

const char* ssid = "**********";
const char* password = "**********";
const char* mqtt_server = "192.168.0.33";

WiFiClient espClient;
PubSubClient client(espClient);
long lastMsg = 0;
char msg[50];
int value = 0;

void setup() {
  pinMode(BUILTIN_LED, OUTPUT);   // Initialize the BUILTIN_LED pin as an output
  Serial.begin(115200);
  
  // initialize the ADC pin as an input
  pinMode(A0, INPUT); 
  
  setup_wifi();
  client.setServer(mqtt_server, 1883);
  client.setCallback(callback);
}

void setup_wifi() {

  delay(10);
  // We start by connecting to a WiFi network
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);

  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
}

void callback(char* topic, byte* payload, unsigned int length) {
  Serial.print("Message arrived [");
  Serial.print(topic);
  Serial.print("] ");
  for (int i = 0; i < length; i++) {
    Serial.print((char)payload[i]);
  }
  Serial.println();

  // Switch on the LED if an 1 was received as first character
  if ((char)payload[0] == '1') {
    digitalWrite(BUILTIN_LED, LOW);   // Turn the LED on (Note that LOW is the voltage level
    // but actually the LED is on; this is because
    // it is acive low on the ESP-01)
  } else {
    digitalWrite(BUILTIN_LED, HIGH);  // Turn the LED off by making the voltage HIGH
  }

}

void reconnect() {
  // Loop until we're reconnected
  while (!client.connected()) {
    Serial.print("Attempting MQTT connection...");
    // Attempt to connect
    if (client.connect("ESP8266Client")) {
      Serial.println("connected");
      // Once connected, publish an announcement...
      client.publish("outTopic", "hello world");
      client.publish("Intellic/Pyramid/Temp","0");
      // ... and resubscribe
      client.subscribe("inTopic");
    } else {
      Serial.print("failed, rc=");
      Serial.print(client.state());
      Serial.println(" try again in 5 seconds");
      // Wait 5 seconds before retrying
      delay(5000);
    }
  }
}

// Declare variables for the analog input from temp sensor
int sensorPin = A0;
int sensorValue = 0;
String mes = "0";



void loop() {
  // Read the sensor
  sensorValue = analogRead(sensorPin);

  if (!client.connected()) {
    reconnect();
  }
  client.loop();
  
  long now = millis();
  if (now - lastMsg > 2000) {
    

    Serial.print("Raw Sensor Value:");
    Serial.println(sensorValue);
    
    lastMsg = now;
    ++value;
    snprintf (msg, 75, "hello world #%ld", value);
    Serial.print("Publish message: ");
    Serial.println(msg);
    client.publish("outTopic", msg);
    mes = String(sensorValue);
    client.publish("Intellic/Pyramid/Temp",(char*)mes.c_str());
  }
}


  1. Subscribe to the new topics in the Raspberry Pi
  • mosquitto_sub -d -t Intellic/Pyramid/Temp
  • mosquitto_sub -d -t outTopic
  1. Confirm that the updates are showing up in the Raspberry Pi and MQTT Spy
  2. Revel in your glory… you just successfully set up an ESP8266 with LM35 temperature sensor to publish to your MQTT Broker!
MQTT-Spy Testing Topics from Arduino


Step 4. Install and Setup the Cirrus Link MQTT Modules in Ignition

Download Ignition and the Cirrus Link Modules here. Documentation for the modules are here.

  1. Install Ignition and Modules
  2. Configure MQTT Engine for your broker
  3. Create Custom Namespace with # to subscribe to all topics
  4. Test tags in Ignition
  5. Revel in your glory… you have successfully setup Ignition to talk to your broker over MQTT!

Navigate to the Gateway Homepage and Open MQTT Engine Settings

No alt text provided for this image

Configure a New MQTT Server

Configure a New MQTT Server

Create a Custom NameSpace and Subscribe to # (all topics)

Create a Custom NameSpace and Subscribe to # (all topics)

Launch a Designer, Check Your Tags and Build a Demo Project!

Launch a Designer, Check Your Tags and Build a Demo Project!


Step 5. Setup Kepserver IOT Gateway

This process is straight forward… download Kepserver and install. Create a new agent (that points to your broker) under the IOT Gateway and drop some tags in. The video link at the beginning of this post covers the details very well.

Step 6. Build Your Demo Project

Once you have tags in Ignition, building a project is the same as with traditional tags. The difference here is that as soon as new topics are published to the broker, they will just show up in the tag structure under the MQTT Engine. I like to call this Self Aware SCADA.

There you have it… a simple demo in Ignition using a Raspberry Pi 3, Arduino ESP8266, MQTT-Spy and Kepserver IOT Gateway.

For a more detailed discussion about the implications of MQTT and the future of SCADA and the Industrial Automation space, please subscribe to our YouTube Channel here.

Thanks for reading!

Blessings,

Walker D Reynolds



Alexey Karpin

Master of Business Administration - MBA at Международный Институт Менеджмента ЛИНК

2 周

Very inspiring video, thanks for sharing the implementation details! In video (15:35) the author emphasizes that the broker would not send the old value, only the changed value. In the C code above, the temperature is published every 2 seconds regardless of the value: "long now = millis(); if (now - lastMsg > 2000) {" Of course we can rewrite this and compare temperature value (we'd have to agree on the amount change that is meaningful for the application. e.g. 0,1 deg) Can we also filter out minor temperature changes inside Mosquitto (running on Raspberry)? And overall when data is considered changed and what is the good place to configure such settings in bigger projects?

回复
Vaibhav Joshi

Working as Associate Consultant at Infosys

10 个月
Prasanna Balakrishnan

Pharma Manufacturing IT | Werum PASX MES | Emerson Syncade MES | Yokogawa CentumVP DCS

5 年

Thanks, Walker Reynolds

要查看或添加评论,请登录

Walker Reynolds的更多文章

社区洞察

其他会员也浏览了