Skip to main content
All CollectionsConnect your Devices
Connect a WAGO PFC200 to Ubidots using a Wago App: Energy Data Management
Connect a WAGO PFC200 to Ubidots using a Wago App: Energy Data Management

This guide goes through the steps required to connect a WAGO PFC200 to Ubidots using the WAGO's Energy Data Management application.

Alejandro Mora Chica avatar
Written by Alejandro Mora Chica
Updated over 2 months ago

We present an alternative method for connecting a WAGO PFC200 to Ubidots through a specialized WAGO application: Energy Data Management. This approach does not require the use of the Codesys tool.

Requirements

1. WAGO PFC200 Controller

WAGO's PFC200 Controller is an industrial grade PLC that facilitates the control and visualization of your projects thanks to the real-time-capable Linux operating system and Codesys. Its unrivalled flexibility unlocks a lot of configuration options for digital and analog I/O modules, alongside specialty modules boasting distinct potentials, powers, and signals—all within a single, consolidated device.

2. Ubidots setup

WAGO's Energy Data Management application can establish connections with any MQTT Broker by configuring it accordingly through the PLC's web-based management interface. Nevertheless, the data extracted from the I/O modules of the device, and subsequently transmitted to the publish topic, is incompatible with our Ubidots JSON format (as outlined in our separate guide for the MQTT Broker). This implies direct connectivity for transmitting data to a specific device within an Ubidots account is not feasible.

Therefore, we provide the alternative presented in this guide, which involves connecting to our functions broker. By sending your data to an UbiFunction, it undergoes parsing into a format compatible with Ubidots. Subsequently, the parsed data is transmitted to your Ubidots devices. By default, an UbiFunction exclusively accommodates the application/JSON content type. However, it's important to note that not all communication protocols rely on this specific format for data transmission.

In scenarios where alternative formats are employed, you have the option to toggle the "raw function" feature within your UbiFunction, as seen in the image below. This allows you to receive data coming in any format, and parse it into an Ubidots compatible format. Follow this article for any additional information about the raw function feature.

You need to select a POST method and Python 3.11 Lite as the runtime. After making the function live, copy the HTTPS endpoint URL.

The complete code is provided below for your raw UbiFunction. Simply ensure that you copy and paste it into your UbiFunction for seamless implementation and then enter your account's token and your device label.

import requests
import time
import json

# Ubidots configuration
UBIDOTS_URL = "https://industrial.api.ubidots.com"
TOKEN = "" #Enter here your account's token
DEVICE_LABEL = "" #Enter here your device label

def main(args):
print(args)
# Selecting variable label
data = json.loads(args['body'])['topic']
variable_label = str(data.split("/")[-1])

# Building variable payload
payload = json.loads(args['body'])['payload']
value = json.loads(payload.strip('"'))["value"]
ubi_payload = {
variable_label: value
}

# Send data to Ubidots
time.sleep(20)
update_device(DEVICE_LABEL, ubi_payload, TOKEN)

print(ubi_payload)

return {}

# Make a request
def make_request(method, url, headers = None, max_attempts = 5, params = None, data = None, json = None, timeout = 10):
attempts = 1
kwargs = {
"method": method.upper(),
"url": url,
"headers": headers,
"params": params,
"data": data,
"json": json,
"timeout": timeout
}
try:
req = requests.request(**kwargs)
status_code = req.status_code
time.sleep(1)
print("Status code: ", status_code)
while status_code >= 400 and attempts < max_attempts:
req = requests.request(**kwargs)
status_code = req.status_code
attempts += 1
time.sleep(1)
return req

except requests.ConnectionError as e:
print(f"Error de conexion: {e}")
return None

except requests.Timeout as e:
print(f"Connection timeout: {e}")
return None

except Exception as e:
print("[ERROR] There was an error with the request, details:")
print(e)
return None

# Send data to Ubidots
def update_device(device, payload, token):
url = "{}/api/v1.6/devices/{}".format(UBIDOTS_URL, device)
headers = {"X-Auth-Token": token, "Content-Type": "application/json"}
req = make_request("post", url, headers = headers, json = payload, max_attempts = 5)


Note: This function is designed to send data to a single device, as defined in the DEVICE_LABEL variable. However, if you intend to transmit data to multiple devices, you can incorporate a straightforward logic to iterate through various device labels within the main function code. By implementing a loop, you can efficiently send data to all required devices.

3. PFC200 Web-based Management

Once you've configured the UbiFunction, you can access the Web-based Management (WBM) of the PLC to set up the connection to the corresponding MQTT broker. Simply navigate to the following URL:

<PLC_IP_ADDRESS>/wbm/


Subsequently, you'll only need to input your username and password.

Then, go to the "Cloud Connectivity" section → "Connection 1" and type the following MQTT configuration:

  • Cloud platform: MQTT AnyCloud

  • Hostname: functions.ubidots.com

  • Port number: 1883

  • Client ID: An alphanumeric combination. You should select your Ubidots device's ID.

  • User: Enter here your Ubidots account's username.

  • Password: Enter here your Ubidots API token.

Note: The configuration of this broker only needs to be established in this section of the Web-based Management. There's no need to configure it anywhere else, including within the WAGO Application Energy Data Management.

4. WAGO Application Data Energy Management

WAGO Energy Data Management consists of web-based application software combined with a modular control system. It records measurement data for different media along with influencing variables for energy monitoring — all of which are processed for additional analysis, archiving and reporting. To access the app, please go to the following URL:

<PLC_IP_ADDRESS>/webvisu/webvisu.htm

After logging in with your credentials, navigate to the "File" tab and then proceed to the "Cloud Connectivity" module.

In the "MQTT/other cloud platforms" (connection 1 or 2) section, paste the function's URL that you copied during the initial step of the process into the "Main topic" field, with a slight modification:

Here's an example of a function URL copied directly from the UbiFunction:

https://parse.ubidots.com/prv/ubidots/test

However, it's necessary to remove the host portion of the URL, retaining only the path:

/prv/ubidots/test --> Main topic

Then, click on "Open the MQTT Measurement collections":

In the "Mapping"  "Inputs" section, you can configure all the necessary digital and analog inputs that you intend to transmit to your Ubidots device. Each register contains a name, a description, and its corresponding value.

Note: Only numerical values can be transmitted to your Ubidots variables.

Don't forget to save your configuration before closing it.

In the final step, you'll need to click on "Open the MQTT frame settings dialogue".

Here, you need to choose which fields from your measurement collections you want to send to your Ubidots device. The crucial step in this process is selecting the "Object Value" option for each enabled content field.

Now, the UbiFunction will receive all the registers configured in the WAGO application and transmit them to your selected device at Ubidots.

Did this answer your question?