Skip to main content

Using app and global config

Overview

On a Barbara Edge Node, you can define parameters to configure applications using JSON files. Two options are available:

  • appConfig: This is a JSON file defined within the "Configuration" section of the application's card. It is only accessible from the application itself.
  • globalConfig: This is a JSON file defined in the "Global App" card. It is accessible from any application installed on the edge node.

Within these JSON files, you define application-specific parameters that do not require secure storage (in which case, you should use global secrets) and that may change frequently during the application's lifecycle.


Videotutorial

See also...

Configuring appconfig & globalconfig in docker-compose.yaml

No specific tags are required in the docker-compose.yaml file. Applications can directly access these configurations through their source code. Inside the container, the files are located in the following paths:

  • Global Config: /appconfig/global.json
  • App Config: /appconfig/appconfig.json

Hands-on Practice: Using App & Global Config in the MQTT Client application

Let's continue with the MQTT Client example from the previous section. This time, we will send two MQTT messages every five seconds:

  1. Message 1: We will read the topic from the "topic" variable and the message from the "message" variable available in the Global Config JSON file.

  2. Message 2: We will read the topic from the "topic" variable and the message from the "message" variable available in the appConfig JSON file.

Step 1: Define the config in the Global Config card

Navigate to your node's Docker Global Config card and define the necessary configuration:

{
"message": "helloGlobal",
"topic": "test/globalTopic"
}

Step 2: Define the config in the appConfig section of the app card

Go to your application's Config section and define the necessary configuration:

{
"message": "helloLocal",
"topic": "test/localTopic"
}

Step 3: Change the application source code to read the secrets from the environment variables

Modify the "test.py" code as follows:

First, add two new functions to read the configuration files and send the messages:

def getGlobalConfig():
with open('/appconfig/global.json') as json_file:
print("Reading Global Config")
data = json.load(json_file)
try:
print("Variable message: ", data["message"])
print("Variable topic: ", data["topic"])
result = client.publish(data["topic"], data["message"])
print('')
except:
print('Global variables not found')
print('')

def getLocalConfig():
with open('/appconfig/appconfig.json') as json_file:
print("Reading App Config")
try:
data = json.load(json_file)
print("Variable message: ", data["message"])
print("Variable topic: ", data["topic"])
result = client.publish(data["topic"], data["message"])
print('')
except:
print('Local variables not found')
print('')

Then, create a loop that calls these functions every five seconds:

while True:
getGlobalConfig()
getLocalConfig()
time.sleep(5)

Step 4: Upload a new version to the library

Zip your source code and create a new version of the application in your Panel's library.

Step 5: Deploy the app to your node

Deploy the application to your edge node and ensure it connects successfully to the MQTT Broker.

Step 6: Check the MQTT Messages

Use an application such as MQTT Explorer to monitor the messages sent by the application. Modify the configuration in the Global Config and App Config cards and observe how the topics and messages change without needing to restart the application.


Summary

We have explored how to use app-specific and global configurations within applications. Now we understand the difference between App Config, a configuration file defined within the application's card for internal use, and Global Config, which is accessible to any application on the node.