Commit f11975ed by Tref

include esp32 code

parent fb1c0af8
Showing with 63 additions and 0 deletions
#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")){
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment