Module Integration Guides
Linux
Customising device shadow
2 min
every project in bytebeam comes with a default docid yibewj202bfcf4o7ekcv stream the stream by default contains just three fields status , timestamp , and sequence this guide shows how to create additional fields and write data to this stream from your application for that, click on the username at the top right corner of the bytebeam cloud console and navigate to settings here under the stream tab, you can find “ device shadow ” for example, add two new columns device name and arch to the device shadow you can do this by entering the field name and type and clicking the + button after adding both fields your device shadow will look like the below now update your application to push this data to the device demo py import socket import json import time s = socket socket(socket af inet, socket sock stream) s connect(("localhost", 5050)) \# constructs a payload and sends it over tcp to uplink def send data(s, payload) send = json dumps(payload) + "\n" s sendall(bytes(send, encoding="utf 8")) \# add more parameters to device shadow def send device shadow(s, sequence) timestamp = int(time time() 1000) payload = { "stream" "device shadow", "sequence" sequence, "timestamp" timestamp, "device name" "beaglebone black rev c", "arch" "armv7", } print(payload) send data(s, payload) print("starting uplink bridge app") sequence = 1 while true time sleep(10) send device shadow(s, sequence) sequence += 1 demo js const net = require("net"); // connect to the server const client = new net socket(); client connect(5050, "localhost", () => { console log("connected to server"); }); // constructs a payload and sends it over tcp to uplink function senddata(payload) { const send = json stringify(payload) + "\n"; client write(send); } // send device shadow data function senddeviceshadow(sequence) { let timestamp = date now(); let payload = { stream "device shadow", sequence sequence, timestamp timestamp, device name "beaglebone black rev c", arch "armv7", }; console log(payload); senddata(payload); } console log("starting uplink bridge app"); let sequence = 1; setinterval(() => { senddeviceshadow(sequence); sequence++; }, 10000); demo rs use std net tcpstream; use std io {read, write}; use std thread; use std time {duration, systemtime}; use serde json {value, json}; async fn send data(mut stream \&tcpstream, payload serde json value) { let send = format!("{}\n", payload to string()); stream write all(send as bytes()) await unwrap(); } async fn send device shadow(mut stream \&tcpstream, sequence u64) { let timestamp = systemtime now() duration since(systemtime unix epoch) unwrap() as millis(); let payload = json!({ "stream" "device shadow", "sequence" sequence, "timestamp" timestamp, "device name" "beaglebone black rev c", "arch" "armv7" }); println!("{ ?}", payload); send data(\&mut stream, payload) await; } \#\[tokio main] async fn main() { let addr = "localhost 5050"; let mut stream = tcpstream connect(\&addr) await unwrap(); println!("starting uplink bridge app"); let mut sequence = 1; loop { thread sleep(duration from secs(5)); send device shadow(\&mut stream, sequence); sequence += 1; } } demo go package main import ( 	"encoding/json" 	"fmt" 	"net" 	"os" 	"strconv" 	"time" ) // deviceshadow represents the payload structure type deviceshadow struct { 	stream string `json "stream"` 	sequence int `json "sequence"` 	timestamp int64 `json "timestamp"` 	devicename string `json "device name"` 	arch string `json "arch"` } func senddata(conn net conn, payload interface{}) { 	data, = json marshal(payload) 	fmt println(string(data)) 	conn write(append(data, '\n')) } // senddeviceshadow constructs and sends a device shadow payload func senddeviceshadow(conn net conn, sequence int) { 	t = time now() unixnano() / int64(time millisecond) 	payload = deviceshadow{ 	 stream "device shadow", 	 sequence sequence, 	 timestamp t, 	 devicename "beaglebone black rev c", 	 arch "armv7", 	} 	fmt println(payload) 	senddata(conn, payload)(conn, payload) } func main() { 	conn, err = net dial("tcp", "localhost 5050") 	if err != nil { 	 fmt println("error connecting ", err error()) 	 os exit(1) 	} 	defer conn close() 	fmt println("starting uplink bridge app") 	sequence = 1 	for { 	 time sleep(5 time second) 	 senddeviceshadow(conn, sequence) 	 sequence++ 	} } you should now be able to see the new fields on bytebeam cloud
