Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
trkall
/
T-Diagnostics
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Snippets
Members
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
f11975ed
authored
May 09, 2021
by
Tref
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
include esp32 code
parent
fb1c0af8
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
63 additions
and
0 deletions
esp32MQTT.ino
esp32MQTT.ino
0 → 100644
View file @
f11975ed
#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"
)){
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment