Need help creating a User Interface for GCP IoT project which uses ESP32 and Raspberry Pi 4

Good Day

I am working on a project that involves using the ESP32 microcontroller and the DHT 22 temperature/humidity sensor to create an IoT device that uses UDP transsmission over Wifi to send data to a Raspberry Pi, which acts as my edge device. The Raspberry Pi then sends this data to Google Cloud by establishing an MQTT connection with the cloud which publishes the data to a pubsub topic. I have so far managed to configure the cloud to accept the data using IoT core and Pub Sub and have successfully sent data to my topic in the cloud. I however, would like to use firebase to create a user interface for easier user experience.
I have come across this article; How to check the weather using GCP-Cloud IoT Core with ESP32 and Mongoose OS, written by @Olivier LOURME which details how to do this using Mongoose Os and Javascript but my mqtt code which publishes data to the cloud is in python and whenever I try to initiate the firebase cloud function for it, I keep getting a ‘syntax error: unexpected token R in JSON at position 0 at JSON.parse’ . The mqtt code can be found here: community/ at master · GoogleCloudPlatform/community · GitHub
I would greatly appreciate any help to enable the python code to transmit the data in the correct JSON format to resolve this problem.

Can anyone help with this?

I use GCP, but not for your use-case (IOT).

The error you have:

‘syntax error: unexpected token R in JSON at position 0 at JSON.parse’

Actually is a good hint at what is going on, namely the R your seeing. At a glance my guess is this line

Is what is trying to be parsed to JSON, and since it is just a string, it fails. I’d change that string to a JSON object that you want to pass to the cloud function, as I believe they only accept JSON payloads.

Regardless that is at least a starting point as to what that error is referring to. I’d also recommend limiting the scope of your problem when asking for help. Its one thing to ask for specific help for a specific stack for a specific tutorial with a specific error, its another to get general help for the error and “connect the dots” to what your doing, rather than providing “all the dots” and asking for help. Its a lot more intimidating to think about the problem if the problem is big.

Good luck, hope it helps!

Thank you @bradtaniguchi for your help and incite. Now that you have pointed out this line to me I actually see why the error was being triggered. Now to figure out how to write the JSON object so that it returns the iot data…

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.