Connecting S7-1200 to MindSphere via SIMATIC IOT2040 Gateway

David Krause10 min read
S7-1200SiemensTutorial / How-to
Licensed PE Working through this on a live machine? A Maine-licensed engineer can take it from here — included with IMD hardware, by the hour for everything else. Book an engineer

Overview

Connecting a SIMATIC S7-1200 to the MindSphere cloud platform requires an intermediary gateway because the S7-1200 CPU does not expose an OPC UA Server interface and its standard firmware does not support the encrypted HTTPS transport that MindSphere REST endpoints require. The SIMATIC IOT2040 (6ES7647-0AA00-1YA2) and the dedicated MindConnect IOT2040 (6ES7647-0AA02-1YA2) are the canonical industrial gateways Siemens designed for this role. This article covers the three practical integration paths, the underlying S7 communication mechanics, the data tag mapping, the network and security configuration, and the verification steps that confirm a healthy uplink.

Critical constraint: A standard SIMATIC IOT2040 cannot be reflashed with the MindConnect firmware image to become a MindConnect IOT2040. The MindConnect variant is a separately ordered SKU with a dedicated image, licensing, and Siemens support contract. The two SKUs share the same Intel Quark x86 + Galileo microcontroller hardware but ship with different Yocto Linux images and different MindSphere onboarding certificates.

Connection Path Comparison

Attribute Path A: MindConnect IOT2040 Path B: IOT2040 + MindConnect Library Path C: S7-1200 MQTT + IoT Extension
Hardware MindConnect IOT2040 (6ES7647-0AA02-1YA2) SIMATIC IOT2040 (6ES7647-0AA00-1YA2) S7-1200 + CP 1243-1 or CPU with firmware V4.4+
Cloud transport Native MindConnect agent over HTTPS 443 Custom C/C++ daemon over HTTPS 443 MQTT 1883/8883 to IoT Extension broker
PLC transport Internal MindConnect data source (S7, OPC UA, Modbus) S7 ISO-on-TCP (port 102) via Snap7 Native MQTT publish from S7-1200 user program
Data buffer Onboard MindConnect store-and-forward Optional temp file or in-memory ring IoT Extension time-series store
Development effort Configuration only Moderate (C/C++ application + S7 mapping) Low (TIA Portal MQTT blocks)
MindSphere agent license Included with MindConnect SKU Self-managed MindConnect Lib token IoT Extension subscription

Prerequisites

  1. S7-1200 CPU with firmware V4.2 or later. For the MQTT path, firmware V4.4 or later is required for the built-in MQTT client blocks. Supported CPUs include CPU 1211C, 1212C, 1214C, 1215C, and 1217C.
  2. TIA Portal V15.1 or later for project configuration and firmware update delivery.
  3. Active MindSphere tenant with at least one MindConnect IOT slot, one MindConnect Lib developer token, or an IoT Extension service subscription, depending on the chosen path.
  4. SIMATIC IOT2040 with Yocto Linux image V2.4.0 or later, SSH access enabled, and root credentials rotated from default.
  5. Network reachability from the IOT2040 or S7-1200 outbound to *.mindsphere.io on TCP 443 (HTTPS) or TCP 8883 (MQTTS) through any corporate firewall or proxy.
  6. Time synchronization (NTP) on every component. MindSphere rejects payloads with timestamps that drift more than 60 seconds from server time.

Path A: MindConnect IOT2040 Native Configuration

The MindConnect IOT2040 ships with the MindConnect Linux agent preinstalled. The agent handles S7 polling, store-and-forward buffering, and the secure mTLS handshake to MindSphere automatically.

Step-by-Step

  1. Connect the MindConnect IOT2040 to the engineering network and power it on. The default IP is 192.168.200.1/24 on eth0. Reconfigure via the serial console or the local web UI on https://192.168.200.1 if needed.
  2. Open a browser to the agent's onboard UI at https://<iot-ip> and complete the Initial Commissioning wizard. The wizard prompts for the MindSphere tenant URL, a MindConnect onboarding token, and a device name.
  3. Configure the S7 data source. From the agent UI, add a new data source with the following parameters:
Parameter Value
Source type S7 (ISO-on-TCP)
PLC IP address 192.168.0.10 (example)
Rack / Slot 0 / 1 (S7-1200 default)
Connection resource OP (passive) or PG (active), depends on the number of S7 connections allowed by the CPU
Polling interval 1000 ms (configurable 100 ms – 60 s)
Read area DB, M, I, Q, or process image
  1. Map each DB or memory address to a MindSphere datapoint using the agent's data point configurator. For a real (4-byte float) in DB10 starting at byte 0, the agent expects an address string such as DB10.DBD0 (Data Block, Double Word, offset 0).
  2. Save the configuration and restart the MindConnect agent service: systemctl restart mindconnect-agent
  3. Verify the data source is online in the MindSphere Asset Manager and that datapoints show non-zero sample counts.

Path B: Standard IOT2040 with MindConnect Library (C/C++)

When only a standard IOT2040 is available, the MindConnect Library (C/C++) allows a custom daemon to read S7 tags via the Snap7 open-source client and publish them to MindSphere as time series. The library is delivered as a Yocto SDK package and is documented in the MindSphere developer documentation at documentation.mindsphere.io.

Step-by-Step

  1. Install build dependencies on the IOT2040:
    opkg update
    opkg install gcc git cmake libssl-dev libcurl4-openssl-dev
  2. Clone and build the MindConnect Library:
    git clone https://github.com/mindsphere/mindconnect-c-lib.git
    cd mindconnect-c-lib && mkdir build && cd build
    cmake .. && make && make install
  3. Clone and build the Snap7 client library against the IOT2040's x86 toolchain:
    git clone https://github.com/davenardella/snap7.git
    cd snap7/build/x86_64_linux && make
  4. Write the gateway daemon. The high-level loop is:
// Pseudocode - compile with mindconnect-c-lib and snap7
S7Client plc;
plc.ConnectTo("192.168.0.10", 0, 1, 2); // rack 0, slot 1, conn 2

McClient cloud;
cloud.Initialize("./config.json"); // contains tenant, agent key, secret

while (running) {
    float tag[8];
    plc.DBRead(10, 0, sizeof(tag), &tag); // 32 bytes from DB10

    McTimestamp ts = McGetNow();
    for (int i = 0; i < 8; ++i) {
        cloud.PublishValue("DB10_REAL_" + std::to_string(i), tag[i], ts);
    }
    cloud.Flush();
    std::this_thread::sleep_for(std::chrono::milliseconds(1000));
}
  1. Deploy the daemon as a systemd service /etc/systemd/system/s7-mindsphere.service with Restart=always and a 5-second RestartSec to survive transient network drops.
  2. Activate with systemctl daemon-reload && systemctl enable --now s7-mindsphere and inspect logs via journalctl -u s7-mindsphere -f.
Connection accounting: The S7-1200 CPU allows a finite number of S7 communication resources. The basic CPU permits 6 concurrent S7 connections; CPU models with an additional CP module can extend this. The S7-1200 counts each active OPC UA server session, each PG connection, and each HMI connection against the same budget. Plan the gateway connection as OP (passive) to free the CPU from connection-establishment overhead.

Path C: S7-1200 MQTT Publisher with IoT Extension

From S7-1200 firmware V4.4, the user program can call the TCON, TSEND, and TRCV extended instructions to publish MQTT frames directly to the MindSphere IoT Extension broker. This path removes the IOT2040 from the data plane for the time-series uplink but still relies on outbound internet access from the S7-1200's CP interface.

Step-by-Step

  1. In TIA Portal, open the S7-1200 project, mark the CPU, and add the MQTT client instructions to the program blocks. The instructions are part of the S7-1200 Motion & Logic library, installed automatically with TIA Portal V15.1 or later.
  2. Configure the connection in the Connection Properties dialog:
Parameter Value
Broker address io-ext.mindsphere.io (region-specific)
Port 8883 (MQTTS, TLS 1.2)
Client ID Unique per device, e.g. s71200-sn-A1B2C3
Topic ten/<tenant>/device/<deviceId>/measures
QoS 0 (fire-and-forget) or 1 (at-least-once)
Authentication OAuth 2.0 bearer token (refreshed hourly)
  1. Build a JSON payload in a global DB. A minimal measure frame is:
    {
      "timestamp": "2024-06-12T10:15:00.000Z",
      "values": [
        {"name": "DB10_REAL_0", "value": 23.7},
        {"name": "DB10_REAL_1", "value": 12.4}
      ]
    }
  2. Trigger publication from the OB1 cycle on a 1-second timer using the PUBLISH instruction. Use the CP 1243-1 (6GK7243-1BX30-0XE0) for TLS termination; the basic CPU does not include TLS.
  3. Register the S7-1200 as an IoT Extension device in the MindSphere cockpit and assign the IoT Extension role to the corresponding asset.
Protocol awareness: The S7-1200 cannot terminate TLS 1.2 in the CPU itself. The CP 1243-1 (firmware V3.2 or later) is mandatory for MQTTS connectivity. A pure CPU 1212C without CP cannot be used for Path C.

S7 Communication Protocol Details

All three paths rely on S7 communication as the PLC-side transport. The S7-1200 implements the S7 protocol on top of ISO-on-TCP (RFC 1006) on TCP port 102. The header structure used by every S7 read/write PDU is:

Byte Field Notes
0 Protocol ID Always 0x32 for S7
1 ROSCTR (job type) 0x01 = Job, 0x03 = Ack-Data
2–3 Redundancy ID 0x0000
4–5 PDU reference Per-request counter
6–7 Parameter length Length of parameter block
8–9 Data length Length of data block

The S7-1200 returns a maximum PDU size of 240 bytes. Snap7 and the MindConnect agent handle PDU fragmentation automatically, but custom daemons should not request more than 222 bytes of payload per call to leave headroom for the variable address specification.

Data Tag Mapping Reference

S7 area Address notation (TIA) Snap7 string MindConnect datapoint key
Data block DB10.DBD0 (REAL) DB10.DBD0 DB10_REAL_0
Data block DB10.DBW2 (INT) DB10.DBW2 DB10_INT_1
Data block DB10.DBX4.0 (BOOL) DB10.DBX4.0 DB10_BOOL_2
Merker MW100 (WORD) MW100 MW100
Inputs IW0 IW0 IW0
Outputs QW0 QW0 QW0

Tag names in MindSphere are flat strings with no . separators. Replace dots with underscores in the MindConnect mapping to avoid parsing errors in the Asset Manager.

Network and Security Configuration

  1. Firewall: Allow outbound TCP 443 (HTTPS) and TCP 8883 (MQTTS) from the gateway IP to *.mindsphere.io. Restrict inbound to the engineering VLAN only.
  2. MindSphere authentication: MindConnect agents use OAuth 2.0 client credentials. The onboarding process issues a 4096-bit RSA key pair; the private key is stored at /etc/mindconnect/keys/private.pem with mode 0600. Loss of the private key requires re-onboarding the device.
  3. PLC access protection: Configure CPU access level 3 (read/write) in TIA Portal under CPU Properties > Protection > Access Level. Use a password of at least 10 characters, including upper/lowercase and digits, to block unauthorized S7 reads.
  4. Time sync: Point the IOT2040 and the S7-1200 CP to an internal NTP server. Drift of more than 60 seconds causes MindSphere to discard the batch.

Verification

  1. In MindSphere Cockpit > Asset Manager, confirm the asset shows Connected with a green status indicator. The Last Update timestamp should refresh on every polling interval.
  2. Open MindSphere > Fleet Manager > Insights and create a temporary chart for one of the mapped datapoints. Verify the trace line is continuous with no gaps longer than two polling intervals.
  3. From the IOT2040 shell, check the agent heartbeat:
    curl -k https://localhost:8443/health
    # {"status":"UP","agentVersion":"3.5.1"}
  4. Run a one-shot S7 read from a TIA Portal online session to confirm the gateway and CPU are not contending for connection resources.

Troubleshooting Matrix

Symptom Likely root cause Remediation
Data source Offline in agent UI S7 connection refused; firewall on TCP 102 Verify CPU protection, check S7 connection resource limit, open TCP 102 bidirectionally
Agent registers but no time series arrive Datapoint names contain dots Rename datapoints to alphanumeric plus underscore only
MQTT publish returns B101 error TLS handshake failed Update CP 1243-1 firmware to V3.2+, import the MindSphere root CA into the CP
Intermittent disconnects every 60 s TCP keepalive on the S7 path Enable Keep-Alive on the S7 connection in the agent UI (typical value 30 s)
HTTP 401 from MindSphere REST Expired agent token Re-run the onboarding wizard to rotate the credentials
Snap7 returns CPU returned a malformed PDU PDU size > 222 bytes Split the read into multiple Snap7 calls of ≤ 222 bytes
CPU SF LED steady red Connection resource exhaustion Reduce concurrent PG/HMI/OPC sessions; check Online & Diagnostics > Communication

Official Reference Documentation

Can I convert a standard SIMATIC IOT2040 into a MindConnect IOT2040 by re-flashing the firmware?

No. The MindConnect IOT2040 (6ES7647-0AA02-1YA2) is a separately ordered SKU with a dedicated firmware image, onboarding certificates, and license. Re-flashing a standard IOT2040 will not produce a working MindConnect agent. To run a custom MindSphere gateway on a standard IOT2040, use the MindConnect Library (C/C++) with a self-managed OAuth token.

Does the S7-1200 support OPC UA Server natively?

No. The S7-1200 firmware exposes OPC UA Server only from V4.5 in limited form, and only for the CPU 1215C and 1217C. Most installed bases run V4.2–V4.4 and rely on the S7 protocol (ISO-on-TCP, port 102) as the data-source language for external gateways.

Why does my S7-1200 refuse to connect directly to MindSphere?

The S7-1200 CPU does not implement TLS 1.2 or HTTPS in firmware; MindSphere only accepts encrypted REST traffic. The most common workarounds are (a) terminating TLS on a CP 1243-1 and publishing MQTT, or (b) using a SIMATIC IOT2040 or MindConnect IOT2040 as the HTTPS termination point.

What is the maximum number of S7 connections an S7-1200 can handle?

Standard S7-1200 CPUs allow up to 6 concurrent S7 communication resources, shared across PG, HMI, OPC UA, and S7 gateway connections. Each CP added to the rack brings additional resources. Plan the gateway connection as OP (passive) so the CPU does not spend cycles initiating the TCP handshake.

Which IOT2040 firmware version is required for Snap7 or MindConnect Library?

Use the Yocto Linux image V2.4.0 or later. Earlier images ship with glibc 2.23 and miss several POSIX features required by modern Snap7 and MindConnect Library builds. The image is delivered as IOT2000-SDK-V2.4.0.zip in the Siemens Industry Online Support portal.

Back to blog