--[[ ME system uploader for ComputerCraft (CC: Tweaked). Requires an "ME Bridge" peripheral (Advanced Peripherals) connected to the computer and wired to an Applied Energistics 2 / Refined Storage network. It periodically reads the network contents and POSTs them to the backend's /api/me-system/update endpoint. NOTE: the backend serves HTTPS with a self-signed certificate by default. CC: Tweaked validates TLS certificates, so either: * point API_URL at an http:// endpoint (run the backend with TLS_ENABLED=false, ideally behind a trusted reverse proxy), or * terminate TLS with a proxy that uses a certificate CC trusts. ]] local API_URL = "http://your-server:3000/api/me-system/update" local INTERVAL = 10 -- seconds between uploads local bridge = peripheral.find("meBridge") if not bridge then error("No ME Bridge peripheral found") end local function collect() local items = bridge.listItems() local payload = {} for _, item in ipairs(items) do payload[#payload + 1] = { name = item.name, amount = item.amount or item.count or 0, displayName = item.displayName, } end return payload end local function upload(payload) local body = textutils.serializeJSON(payload) local response, err = http.post(API_URL, body, { ["Content-Type"] = "application/json", }) if not response then print("Upload failed: " .. tostring(err)) return end print("Uploaded " .. #payload .. " items -> " .. response.readAll()) response.close() end print("ME uploader started. Target: " .. API_URL) while true do local ok, payload = pcall(collect) if ok then pcall(upload, payload) else print("Collect failed: " .. tostring(payload)) end sleep(INTERVAL) end