Hi. I’m very new to coding.
I’m currently working on an MQTT project that involves an Arduino (Esp32) with sensors sending data (publishing) to an MQTT Broker and Processing picking up that data (subscribing)from the MQTT Broker and using that data to create art.
Initially, it was Arduino to MQTT Broker to Processing. I got that to work.
Now I’m trying to port my Processing code to p5, but I don’t know where to begin as p5 feels a little different compared to Processing. It’s been frustrating.
Here is my Processing code for the MessageReceived function. Works perfectly fine in Processing:
void messageReceived(String topic, byte[] payload) {
println("new message: " + topic + " - " + new String(payload));
String recData = new String(payload);
String[] list = split(recData, ',');
int plantId = int(list[0]);
int temperature = int(list[1]);
int proximity = int(list[2]);
int humidity = int(list[3]);
print(' ');
print(plantId);
print(' ');
print(temperature);
print(' ');
print(proximity);
print(' ');
print(humidity);
println(' ');
}
I don’t even know how to start with porting that to p5.
I saw an MQTT p5 sketch that had this in its template:
var socket;
// This function is called each time we receive a message from the MQTT-SocketIO bridge
function messageReceived(msg) {
print("mqtt message received! ["+msg.topic+"] >>"+msg.payload+"<<")
// Do something with the payload...
}
I don’t know how to begin porting from Processing to p5
Any help you can give will be much appreciated!
Sorry, it might be obvious to everyone, but I’m very new to coding.