diff --git a/debugMqtt/hw1/main.py b/debugMqtt/hw1/main.py new file mode 100644 index 0000000..d83007f --- /dev/null +++ b/debugMqtt/hw1/main.py @@ -0,0 +1,26 @@ +import paho.mqtt.client as mqtt + + +def on_connect(client, userdata, flags, rc): + print("Connected with result code "+str(rc)) + + # Subscribing in on_connect() means that if we lose the connection and + # reconnect then subscriptions will be renewed. + client.subscribe("Rover/Info") + client.subscribe("Rover/Warn") + client.subscribe("Rover/Error") + client.subscribe("Rover/Info") + + +def on_message(client, userdata, msg): + print(msg.topic+" -> "+str(msg.payload)[2:-1]) + + +if __name__ == '__main__': + client = mqtt.Client() + client.on_connect = on_connect + client.on_message = on_message + + client.connect("dz-pi.hw1.fb4.fh", 1883, 60) + + client.loop_forever() diff --git a/debugMqtt/hw1/main_debug.py b/debugMqtt/hw1/main_debug.py new file mode 100644 index 0000000..b8e61f7 --- /dev/null +++ b/debugMqtt/hw1/main_debug.py @@ -0,0 +1,23 @@ +import paho.mqtt.client as mqtt + + +def on_connect(client, userdata, flags, rc): + print("Connected with result code "+str(rc)) + + # Subscribing in on_connect() means that if we lose the connection and + # reconnect then subscriptions will be renewed. + client.subscribe("Rover/Debug") + + +def on_message(client, userdata, msg): + print(msg.topic+" -> "+str(msg.payload)[2:-1]) + + +if __name__ == '__main__': + client = mqtt.Client() + client.on_connect = on_connect + client.on_message = on_message + + client.connect("dz-pi.hw1.fb4.fh", 1883, 60) + + client.loop_forever() diff --git a/debugMqtt/main.py b/debugMqtt/main.py new file mode 100644 index 0000000..912df6a --- /dev/null +++ b/debugMqtt/main.py @@ -0,0 +1,26 @@ +import paho.mqtt.client as mqtt + + +def on_connect(client, userdata, flags, rc): + print("Connected with result code "+str(rc)) + + # Subscribing in on_connect() means that if we lose the connection and + # reconnect then subscriptions will be renewed. + client.subscribe("Rover/Info") + client.subscribe("Rover/Warn") + client.subscribe("Rover/Error") + client.subscribe("Rover/Info") + + +def on_message(client, userdata, msg): + print(msg.topic+" -> "+str(msg.payload)[2:-1]) + + +if __name__ == '__main__': + client = mqtt.Client() + client.on_connect = on_connect + client.on_message = on_message + + client.connect("192.168.1.2", 1883, 60) + + client.loop_forever() diff --git a/debugMqtt/main_debug.py b/debugMqtt/main_debug.py new file mode 100644 index 0000000..98f4087 --- /dev/null +++ b/debugMqtt/main_debug.py @@ -0,0 +1,23 @@ +import paho.mqtt.client as mqtt + + +def on_connect(client, userdata, flags, rc): + print("Connected with result code "+str(rc)) + + # Subscribing in on_connect() means that if we lose the connection and + # reconnect then subscriptions will be renewed. + client.subscribe("Rover/Debug") + + +def on_message(client, userdata, msg): + print(msg.topic+" -> "+str(msg.payload)[2:-1]) + + +if __name__ == '__main__': + client = mqtt.Client() + client.on_connect = on_connect + client.on_message = on_message + + client.connect("192.168.1.2", 1883, 60) + + client.loop_forever() diff --git a/src/config.h b/src/config.h index 3d1cc5d..60f9229 100644 --- a/src/config.h +++ b/src/config.h @@ -65,7 +65,7 @@ // PS3 Controller // ESP32 MAC BL 24:62:AB:F2:4B:3A -#define RHEDE +#define HW1 //Network config RHEDE #ifdef RHEDE @@ -77,11 +77,26 @@ #define MQTT_SERVER 0x0701A8C0 //192.168.1.7 #define MQTT_PORT 1883 #define MQTT_BUFFER_SITE 128 +#define MQTT_AUTH #define MQTT_USER "kleiax" #define MQTT_PASSWORD "p?{$_~5%hBM7wrcFkr55KWr#" #define NTP_SERVER 0x0100a8c0 //192.168.0.1 #endif //RHEDE + +//Network config HW1 +#ifdef HW1 +#define WLAN_SSID "hw1_gast" +#define WLAN_PASSWORD "KeineAhnung" +#define WLAN_IP 0x3400a8c0 //192.168.0.67 +#define WLAN_SUBNETMASK 0x00FFFFFF //255.255.255.0 +#define WLAN_GATEWAY 0x0100a8c0 //192.168.0.1 +#define MQTT_SERVER "dz-pi.hw1.fb4.fh" +#define MQTT_PORT 1883 +#define MQTT_BUFFER_SITE 128 +#define NTP_SERVER "2.de.pool.ntp.org" +#endif //HW1 + //Network config FRENZY #ifdef FRENZY #define WLAN_SSID "GNX7EDD84-2" diff --git a/src/main.cpp b/src/main.cpp index 25f058d..8015683 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -38,7 +38,7 @@ ConsolControl consolControl; IPAddress local_IP(WLAN_IP); IPAddress gateway(WLAN_GATEWAY); IPAddress subnet(WLAN_SUBNETMASK); -IPAddress mqtt_server(MQTT_SERVER); +// IPAddress mqtt_server(MQTT_SERVER); WiFiClient wifi_client; PubSubClient mqtt_client(wifi_client); @@ -71,7 +71,8 @@ void setup() { Serial.println("IP address: "); Serial.println(WiFi.localIP()); - mqtt_client.setServer(mqtt_server, MQTT_PORT); + // mqtt_client.setServer(mqtt_server, MQTT_PORT); + mqtt_client.setServer(MQTT_SERVER, MQTT_PORT); reconnectMqtt(); configTime(3600, 3600, "192.168.1.2"); @@ -144,7 +145,12 @@ void reconnectMqtt() { String clientId = "ESP32Rover-"; clientId += String(random(0xffff), HEX); // Attempt to connect + #ifdef MQTT_AUTH if (mqtt_client.connect(clientId.c_str(), MQTT_USER, MQTT_PASSWORD)) { + #endif //MQTT_AUTH + #ifndef MQTT_AUTH + if (mqtt_client.connect(clientId.c_str())) { + #endif //MQTT_AUTH Serial.println("connected"); // Once connected, publish an announcement... mqtt_client.publish("Rover/Info", "Connected to Mqtt-Broker"); diff --git a/src/moveControl.cpp b/src/moveControl.cpp index ed1922e..ebd330a 100644 --- a/src/moveControl.cpp +++ b/src/moveControl.cpp @@ -10,7 +10,7 @@ MoveControl::MoveControl() { PID_LEFT_P, PID_LEFT_I, PID_LEFT_D, DIRECT); this->right_pid = new PID( &this->wheelspeed_right, - &this->left_pid_out, + &this->right_pid_out, &this->wheelspeed_right_target, PID_RIGHT_P, PID_RIGHT_I, PID_RIGHT_D, DIRECT);