I'm about to cry
This commit is contained in:
@@ -30,19 +30,46 @@ client_controller = ClientController(app, auth_data, "https://192.168.15.120:800
|
|||||||
message_controller = MessageController(app, auth_data, "https://192.168.15.120:8000")
|
message_controller = MessageController(app, auth_data, "https://192.168.15.120:8000")
|
||||||
|
|
||||||
|
|
||||||
def handle_message_received(topic:str, payload:str):
|
def handle_message_received(topic: str, payload: str):
|
||||||
try :
|
try:
|
||||||
parsed = json.loads(payload)
|
print("=== MQTT MESSAGE RECEIVED ===", flush=True)
|
||||||
print("Raw payload:", payload, flush=True)
|
print("Raw payload:", payload, flush=True)
|
||||||
print("Payload type:", type(payload), flush=True)
|
print("Payload type:", type(payload), flush=True)
|
||||||
print("Parsed payload:", parsed, flush=True)
|
|
||||||
print(payload, flush=True)
|
data = json.loads(payload)
|
||||||
|
print("Parsed payload:", data, flush=True)
|
||||||
|
|
||||||
url = "https://192.168.15.125:1880/message/receive"
|
url = "https://192.168.15.125:1880/message/receive"
|
||||||
response = requests.post(url, json=json.dumps({"payload" : payload}), verify=False)
|
|
||||||
print(response.json(), flush=True)
|
response = requests.post(
|
||||||
|
url,
|
||||||
|
json=data,
|
||||||
|
verify=False,
|
||||||
|
timeout=5
|
||||||
|
)
|
||||||
|
|
||||||
|
print("=== NODE-RED RESPONSE ===", flush=True)
|
||||||
|
print("Status code:", response.status_code, flush=True)
|
||||||
|
print("Headers:", response.headers, flush=True)
|
||||||
|
print("Raw response:", repr(response.text), flush=True)
|
||||||
|
|
||||||
|
if response.text.strip():
|
||||||
|
content_type = response.headers.get("Content-Type", "")
|
||||||
|
if content_type.startswith("application/json"):
|
||||||
|
print("Response JSON:", response.json(), flush=True)
|
||||||
|
else:
|
||||||
|
print("Response is not JSON", flush=True)
|
||||||
|
else:
|
||||||
|
print("Node-RED returned an empty response body", flush=True)
|
||||||
|
|
||||||
|
except json.JSONDecodeError as e:
|
||||||
|
print("Incoming payload is NOT valid JSON:", e, flush=True)
|
||||||
|
|
||||||
|
except requests.RequestException as e:
|
||||||
|
print("HTTP request to Node-RED failed:", e, flush=True)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("Payload is NOT valid JSON:", e, flush=True)
|
print("Unexpected error:", e, flush=True)
|
||||||
|
|
||||||
def start_mqtt(data : AuthData):
|
def start_mqtt(data : AuthData):
|
||||||
client_id = data.get_client_id()
|
client_id = data.get_client_id()
|
||||||
|
|||||||
Reference in New Issue
Block a user