From f11975ed275528e8ec140c686cbfafcc59c7c2cb Mon Sep 17 00:00:00 2001
From: Tref <trkall@ttu.ee>
Date: Sun, 9 May 2021 22:48:46 +0300
Subject: [PATCH] include esp32 code

---
 esp32MQTT.ino | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 63 insertions(+)
 create mode 100644 esp32MQTT.ino

diff --git a/esp32MQTT.ino b/esp32MQTT.ino
new file mode 100644
index 0000000..cd18888
--- /dev/null
+++ b/esp32MQTT.ino
@@ -0,0 +1,63 @@
+#include <WiFi.h>
+#include <PubSubClient.h>
+#include <SPI.h>
+#include <Arduino.h>
+
+#define PORT 1883
+const char* WIFI_SSID = "Telia-9E1E41";
+const char* WIFI_PASS = "XPC47UPGRT";
+const char* server = "192.168.1.188";
+
+WiFiClient client;
+PubSubClient mqttClient(client);
+void setup() {
+  Serial.begin(9600);
+  // put your setup code here, to run once:
+  WiFi.begin(WIFI_SSID, WIFI_PASS);
+  while (WiFi.status() != WL_CONNECTED)
+  {
+    delay(3000);
+  }
+  mqttClient.setServer(server, PORT);
+  // put your setup code here, to run once:
+  delay(5000);
+  while(1){
+    if(mqttClient.connect("ardu")){
+      break;
+    }
+  }
+  mqttClient.setCallback(subscribeReceive);
+}
+
+void loop() {
+  // put your main code here, to run repeatedly:
+  while (Serial.available()) {
+    String s = Serial.readString();
+    int n = s.length();
+    char c[n + 1];
+    strcpy(c, s.c_str());
+    switch(c[0]){
+      case 'p':
+        mqttClient.publish("/master/app/server/diagnostics/ecu/errorreading", c);
+        Serial.write("done");
+        break;
+    }
+  }
+}
+
+void MQTTdataParser(byte* payload, char str[], unsigned int length){
+  for(int i = 0; i < length; i++)
+    {
+      //Serial.print(char(payload[i]));
+      str[i] = char(payload[i]);
+    }
+}
+
+void subscribeReceive(char* topic, byte* payload, unsigned int length)
+{
+  char str[length+1];
+  MQTTdataParser(payload, str, length);
+  if(strcmp(topic, "/master/app/server/diagnostics/user/grpreading")){
+
+  }
+}
--
libgit2 0.25.0