Rover
https://editor.p5js.org/hobye/sketches/MVQKBNn3k
https://github.com/m5stack/M5StickC/blob/master/examples/KIT/JoyC_%26_RoverC/Remote/Remote.ino
https://docs.m5stack.com/en/hat/hat_roverc_pro
https://github.com/m5stack/M5-ProductExampleCodes
https://editor.p5js.org/hobye/sketches/zVHHkESmO
Simple rover example code:
https://drive.google.com/file/d/1zy_l0FY-DbQAxWbC-NwnLaYEtpNoPq28/view?usp=sharing
Use this p5js example: https://editor.p5js.org/hobye/sketches/MVQKBNn3k
#include <WiFi.h>
#include <PubSubClient.h>
// Connection info.
const char* ssid = "hobye";
const char* password = "XXXX";
const char* mqttServer = "mqtt.pndsn.com";
const int mqttPort = 1883;
const char* clientID = "pub-c-ce059109-494f-44d5-9567-1b9f275d9f88/sub-c-9844966a-2c1c-11ec-b636-021bdbd01fcd/CLIENT_ID";
const char* channelName = "channel1";
WiFiClient MQTTclient;
PubSubClient client(MQTTclient);
void callback(char* topic, byte* payload, unsigned int length) {
String payload_buff;
for (int i=0;i<length;i++) {
payload_buff = payload_buff+String((char)payload[i]);
}
Serial.println(payload_buff); // Print out messages.
}
long lastReconnectAttempt = 0;
boolean reconnect() {
if (client.connect(clientID)) {
client.subscribe(channelName); // Subscribe to channel.
}
return client.connected();
}
void setup() {
Serial.begin(9600);
Serial.println("Attempting to connect...");
WiFi.begin(ssid, password); // Connect to WiFi.
if(WiFi.waitForConnectResult() != WL_CONNECTED) {
Serial.println("Couldn't connect to WiFi.");
while(1) delay(100);
}
client.setServer(mqttServer, mqttPort); // Connect to PubNub.
client.setCallback(callback);
lastReconnectAttempt = 0;
}
void loop() {
if (!client.connected()) {
long now = millis();
if (now - lastReconnectAttempt > 5000) { // Try to reconnect.
lastReconnectAttempt = now;
if (reconnect()) { // Attempt to reconnect.
lastReconnectAttempt = 0;
}
}
} else { // Connected.
client.loop();
client.publish(channelName,"Hello world!"); // Publish message.
delay(5000);
}
}