Setting Up Datacake HTTP Connections
Send device data from ALPON X5 AI or ALPON X4 to Datacake over the HTTP API: build a Python HTTP client container, push it to the Sixfab Container Registry, deploy it through ALPON Cloud, configure the Datacake payload decoder, and test the endpoint with cURL.
Set up Datacake HTTP connections on ALPON
Publish device data from your ALPON X5 AI or ALPON X4 to Datacake over its HTTP API for real-time monitoring and visualization. This guide packages a Python HTTP client as a container, deploys it through ALPON Cloud, configures the Datacake payload decoder, and verifies the endpoint with cURL.
Build a small Python container that POSTs a JSON payload with device,
temperature, and humidity fields to your Datacake HTTP API endpoint, push it to your
Sixfab Container Registry, then deploy it from the Applications → Deploy
panel on ALPON Cloud with the DATACAKE_API_ENDPOINT,
DATACAKE_INTEGRATION_TOKEN, and DEVICE_SERIAL environment variables. In Datacake,
add an HTTP payload decoder to map the JSON keys to device fields; the ALPON X5 AI or
ALPON X4 then sends a reading every 10 seconds.
Overview
The Datacake HTTP API offers a simple and efficient way to send device data to the cloud, enabling integration with the Datacake platform for real-time monitoring and visualization. This guide walks you through deploying a Datacake HTTP client on your ALPON X5 AI or ALPON X4 to publish messages, complete with setup instructions, code, and testing steps.
The steps are identical on ALPON X4 and ALPON X5 AI. For detailed API options, refer to the Datacake HTTP API documentation.
- ALPON device: an ALPON X5 AI or ALPON X4, powered on, fully operational, and connected to ALPON Cloud.
- Datacake account: sign up for a Datacake account to access the HTTP API integration features.
- Datacake integration token: generate this token in your Datacake account under the HTTP API integration settings for secure authentication.
- Docker installed: on your local machine, for building the container image.
-
1
Create the Dockerfile
To enable Datacake HTTP communication you will create a containerized environment with a custom Python script. On your local machine, create a file named
Dockerfilewith the following content to set up a lightweight environment with the necessary tools:DockerfileFROM alpine:latest RUN apk update && apk add \\ curl \\ python3 \\ py3-pip \\ bash RUN pip3 install requests WORKDIR /app COPY datacake_http_client.py /app/ CMD ["python3", "/app/datacake_http_client.py"] -
2
Create the Datacake HTTP client script
Create a Python file named
datacake_http_client.pyto handle data transmission to Datacake. It reads the endpoint and device serial from theDATACAKE_API_ENDPOINTandDEVICE_SERIALenvironment variables and posts a sample temperature and humidity reading every 10 seconds:python · datacake_http_client.pyimport requests import time import json import random import os # Datacake HTTP API configuration api_endpoint = os.environ.get("DATACAKE_API_ENDPOINT", "your-datacake-http-endpoint") device_serial = os.environ.get("DEVICE_SERIAL", "your-device-serial") # Datacake data format def create_datacake_payload(device_serial, temperature, humidity): data = { "device": device_serial, "temperature": temperature, "humidity": humidity } return data # Function to send HTTP POST request to Datacake def send_to_datacake(payload): try: response = requests.post(api_endpoint, json=payload) print(f"Status Code: {response.status_code}") print(f"Response: {response.text}") return response.status_code == 200 except Exception as e: print(f"Error sending data to Datacake: {e}") return False # Publish messages every 10 seconds try: print(f"Starting Datacake HTTP client for device: {device_serial}") while True: # Create sample data temperature = round(random.uniform(20, 30), 2) humidity = round(random.uniform(40, 60), 2) # Create Datacake formatted payload payload = create_datacake_payload(device_serial, temperature, humidity) print(f"Sending data: Temperature: {temperature}°C, Humidity: {humidity}%") # Send data to Datacake success = send_to_datacake(payload) if success: print("Data sent successfully to Datacake!") else: print("Failed to send data to Datacake.") # Wait before next reading time.sleep(10) except KeyboardInterrupt: print("Exiting...") -
3
Build the Docker image
In your terminal, navigate to the directory containing the
Dockerfileanddatacake_http_client.py, then build the image on your local machine forlinux/arm64:bash · build the imagedocker build --platform=linux/arm64 -t datacake-http-alpon-x4:latest .
-
4
Push the image to ALPON Cloud
Log in to ALPON Cloud and open the Sixfab Container Registry page. Click + Add Container and follow the prompts to push the
datacake-http-alpon-x4image to the Sixfab Container Registry.Deploy ApplicationsVisit the Deploy Applications page for all the necessary details on pushing your container image to the Sixfab Container Registry.
-
5
Deploy the container on ALPON
Go to the Applications section of your asset on ALPON Cloud and click + Deploy. In the Deploy Container window, use these settings:
Container Namedatacake-http-clientImageThedatacake-http-alpon-x4image and tag you pushed to the Sixfab Container Registry.EnvironmentClick + Add More in the environment section and add the three variables in the table below.Key Value DATACAKE_API_ENDPOINTyour-datacake-endpointDATACAKE_INTEGRATION_TOKENyour-integration-tokenDEVICE_SERIALyour-device-serialThe endpoint URL and integration token come from the HTTP API integration in your Datacake account (the endpoint is also shown next to the payload decoder in step 6). Click + Deploy to deploy the Datacake client.
-
6
Configure the Datacake decoder
To process incoming data in Datacake, configure a decoder function in your account. Log in to your Datacake account and navigate to your device, open the Configuration tab, and locate the HTTP Payload Decoder section. Add the following JavaScript decoder function to parse and process the incoming data:
javascript · HTTP payload decoderfunction Decoder(request) { var payload = JSON.parse(request.body) var serialNumber = payload.device try { var datacakeUUID = deviceSerialToId[serialNumber] var temperatureInDatabase = measurements[datacakeUUID]["TEMPERATURE"].value var temperatureInPayload = payload["temperature"] if (temperatureInPayload > temperatureInDatabase) { payload["temperature_higher"] = true } } catch (e) { console.log(JSON.stringify(e)) console.log("Error reading measurement from the device. Does the field exist?") } try { var datacakeUUID = deviceSerialToId[serialNumber] var temperatureLimit = configurationValues[datacakeUUID]["TEMPERATURE_LIMIT"] if (payload["temperature"] > temperatureLimit) { payload["temperature_limit_reached"] = true } } catch (e) { console.log(JSON.stringify(e)) console.log("Error parsing Configuration Field") } var timestamp = Math.floor(Date.now() / 1000); var result = Object.keys(payload).map(function(key) { if (key !== "device") { return { device: payload.device, field: key.toUpperCase(), value: payload[key], timestamp: timestamp }; } }); return result }Save the decoder and note the HTTP Endpoint URL provided by Datacake — this is the value of the
DATACAKE_API_ENDPOINTenvironment variable. -
7
Test the integration with cURL
To verify your Datacake HTTP API setup, send one request manually from your terminal. The request the container makes has this shape:
MethodPOSTtoyour-datacake-endpointContent-Typeapplication/jsonAuthorizationBearer your-integration-tokenBodyJSON withdevice,temperature, andhumiditykeys.bash · test the endpointcurl -X POST -H "Content-Type: application/json" \\ -H "Authorization: Bearer your-integration-token" \\ -d '{"device":"your-device-serial","temperature":25.4,"humidity":48.3}' \\ your-datacake-endpoint
A successful response looks like this:
json · response{ "method": "POST", "GET": {}, "POST": {}, "body": "{\\"device\\":\\"your-device-serial\\",\\"temperature\\":25.4,\\"humidity\\":48.3}", "headers": { "Content-Length": "68", "Content-Type": "application/json" }, "path": "/integrations/api/your-integration-token" }
- The
datacake-http-clientcontainer shows as running in the Applications section. - The cURL test returns the JSON response above with your payload echoed in
body. - Your Datacake device shows new
TEMPERATUREandHUMIDITYvalues every 10 seconds.
Once deployed, your ALPON sends temperature and humidity data to Datacake every 10 seconds. Log in to your Datacake account to view the data in your dashboards or configure alerts. With the Datacake HTTP client running on the ALPON, you are ready to monitor and analyze your device data.
Production image policy: Replace floating
:latestreferences with a reviewed immutable tag or digest, then record the selected version for rollback.
Updated 18 days ago
