UbiMakerMaka Hernandez
Published © CC BY-NC-SA

Siemens SIMATIC IOT2000 Series to Ubidots + Arduino IDE

Program the SIMATIC 2000 series using the Arduino IDE and send the data to Ubidots.

BeginnerProtip3 hours2,017
Siemens SIMATIC IOT2000 Series to Ubidots + Arduino IDE

Things used in this project

Hardware components

Ethernet cable
×1
SD card
×1
24V/14.6A Power Supply
OpenBuilds 24V/14.6A Power Supply
×1
Arduino IDE Siemens SIMATIC IOT 2040
×1

Software apps and online services

Arduino IDE
Arduino IDE
Yocto Project
Yocto Project

Story

Read more

Code

Code snippet #25

Plain text
# /etc/network/interfaces -- configuration file for ifup(8), ifdown(8)

# The loopback interface
auto lo
iface lo inet loopback

# Wired interfaces
auto eth0
iface eth0 inet static
        address 192.168.200.1
        netmask 255.255.255.0

auto eth1
iface eth1 inet dhcp

Code snippet #26

Plain text
# /etc/network/interfaces -- configuration file for ifup(8), ifdown(8)

# The loopback interface
auto lo
iface lo inet loopback

# Wired interfaces
auto eth0
iface eth0 inet static
        address 192.168.200.1
        netmask 255.255.255.0

auto eth1
iface eth1 inet dhcp

Code snippet #27

Plain text
# /etc/network/interfaces -- configuration file for ifup(8), ifdown(8)

# The loopback interface
auto lo
iface lo inet loopback

# Wired interfaces
auto eth0
iface eth0 inet dhcp

Code snippet #28

Plain text
# /etc/network/interfaces -- configuration file for ifup(8), ifdown(8)

# The loopback interface
auto lo
iface lo inet loopback

# Wired interfaces
auto eth0
iface eth0 inet dhcp

Code snippet #29

Plain text
#include <EthernetClient.h>

const char server[] = "things.ubidots.com";
const char device_label[] = "simatic-iot2000"; // the device label to be send
const char variable_label[] = "humidity"; // the variable label to be send
const char token[] = "your_ubidots_token_here"; // assign your Ubidots Token

char* payload  = (char *) malloc(sizeof(char) * 20);  

/* Initialize the Ethernet client library */
EthernetClient client;

void setup() {
  Serial.begin(9600);
  while (!Serial) {
    ; /* wait for serial port to connect */
  }

  /* Analog input configuration */
  const int IOShield_U0 = A0;  
  int value = analogRead(IOShield_U0);
  /* Build the payload to be send. e.i -> {"humidity": 55} */
  sprintf(payload, "{\"%s\":%d}", variable_label, value);

  Serial.println("connecting...");
  
  /* if you get a connection, report back via serial: */
  if (client.connect(server, 80)) {
    Serial.println("connected");
    /* Make the HTTP request to the server*/
    client.print(F("POST /api/v1.6/devices/"));
    client.print(device_label);
    client.println(F(" HTTP/1.1"));
    client.println(F("Host: things.ubidots.com"));
    client.println(F("User-Agent: siemenes/1.1"));
    client.print(F("X-Auth-Token: "));
    client.println(token);
    client.println(F("Connection: close"));
    client.println(F("Content-Type: application/json"));
    client.println(F("Content-Length: 17"));
    client.println();
    client.print(payload);
    client.println();
    free(payload);
  }
  else {
    /* if you didn't get a connection to the server: */
    Serial.println("connection failed");
  }
}

void loop()
{
  /* if there are incoming bytes available
     from the server, read them and print them: */
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }

  /* if the server's disconnected, stop the client: */
  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();

    /* do nothing forevermore: */
    for (;;)
      ;
  }
}

Code snippet #30

Plain text
#include <EthernetClient.h>

const char server[] = "things.ubidots.com";
const char device_label[] = "simatic-iot2000"; // the device label to be send
const char variable_label[] = "humidity"; // the variable label to be send
const char token[] = "your_ubidots_token_here"; // assign your Ubidots Token

char* payload  = (char *) malloc(sizeof(char) * 20);  

/* Initialize the Ethernet client library */
EthernetClient client;

void setup() {
  Serial.begin(9600);
  while (!Serial) {
    ; /* wait for serial port to connect */
  }

  /* Analog input configuration */
  const int IOShield_U0 = A0;  
  int value = analogRead(IOShield_U0);
  /* Build the payload to be send. e.i -> {"humidity": 55} */
  sprintf(payload, "{\"%s\":%d}", variable_label, value);

  Serial.println("connecting...");
  
  /* if you get a connection, report back via serial: */
  if (client.connect(server, 80)) {
    Serial.println("connected");
    /* Make the HTTP request to the server*/
    client.print(F("POST /api/v1.6/devices/"));
    client.print(device_label);
    client.println(F(" HTTP/1.1"));
    client.println(F("Host: things.ubidots.com"));
    client.println(F("User-Agent: siemenes/1.1"));
    client.print(F("X-Auth-Token: "));
    client.println(token);
    client.println(F("Connection: close"));
    client.println(F("Content-Type: application/json"));
    client.println(F("Content-Length: 17"));
    client.println();
    client.print(payload);
    client.println();
    free(payload);
  }
  else {
    /* if you didn't get a connection to the server: */
    Serial.println("connection failed");
  }
}

void loop()
{
  /* if there are incoming bytes available
     from the server, read them and print them: */
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }

  /* if the server's disconnected, stop the client: */
  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();

    /* do nothing forevermore: */
    for (;;)
      ;
  }
}

Credits

UbiMaker

UbiMaker

53 projects • 228 followers
Maker @ ubidots.com
Maka Hernandez

Maka Hernandez

29 projects • 122 followers

Comments