Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Praktika GruLaIT
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Marc Kühne
Praktika GruLaIT
Commits
cd7cad0c
Commit
cd7cad0c
authored
4 years ago
by
Marc Kühne
Browse files
Options
Downloads
Patches
Plain Diff
tested
parent
fffff39d
Branches
master
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
Test/Test/src/SimulatedESP8266.cpp
+77
-0
77 additions, 0 deletions
Test/Test/src/SimulatedESP8266.cpp
Test/Test/src/SimulatedESP8266.h
+32
-0
32 additions, 0 deletions
Test/Test/src/SimulatedESP8266.h
Test/Test/src/main.cpp
+19
-0
19 additions, 0 deletions
Test/Test/src/main.cpp
with
128 additions
and
0 deletions
Test/Test/src/SimulatedESP8266.cpp
0 → 100644
+
77
−
0
View file @
cd7cad0c
/**
* @file SimulatedESP8266.cpp
* @author Samuel Helbling (samuel.helbling@ost.ch)
* @brief
* @version 0.1
* @date 2021-04-29
*
* @copyright Copyright (c) 2021
*
*/
#include
"Arduino.h"
#include
"SimulatedESP8266.h"
#define DEBUG false // set to TRUE to get more informations during runtime
uint8_t
m_responseBuffer
[
300
]
=
{
0
};
SimulatedESP8266
::
SimulatedESP8266
(
int
rxPin
,
int
txPin
)
:
rxPin
{
rxPin
},
txPin
{
txPin
}
{
}
void
SimulatedESP8266
::
setup
()
{
espSerial
.
begin
(
115200
);
espData
(
"AT+RST"
,
10
,
DEBUG
);
//Reset the ESP8266 module
espData
(
"AT+CWMODE=1"
,
10
,
DEBUG
);
//Set the ESP mode as station mode
espData
(
"AT+CWJAP=
\"
VBB
\"
,
\"
12345
\"
"
,
10
,
DEBUG
);
//Connect to WiFi network
Serial
.
println
(
"ESP ready"
);
}
String
SimulatedESP8266
::
httpGet
(
String
host
,
String
endpoint
,
String
protocol
=
"80"
)
{
Serial
.
println
(
"Sending HTTP Get-Request"
);
String
sendData
=
"GET "
+
endpoint
;
espData
(
"AT+CIPMUX=1"
,
10
,
DEBUG
);
//Allow multiple connections
espData
(
"AT+CIPSTART=0,
\"
TCP
\"
,
\"
"
+
host
+
"
\"
,"
+
protocol
,
10
,
DEBUG
);
espData
(
"AT+CIPSEND=0,"
+
String
(
sendData
.
length
()
+
4
),
10
,
DEBUG
);
espSerial
.
find
(
'>'
);
String
response
=
espData
(
sendData
,
10
,
DEBUG
);
espData
(
"AT+CIPCLOSE=0"
,
10
,
DEBUG
);
return
response
;
}
String
SimulatedESP8266
::
httpPost
(
String
host
,
String
endpoint
,
String
payload
,
String
protocol
=
"80"
)
{
Serial
.
println
(
"Sending HTTP Post-Request"
);
String
sendData
=
"POST "
+
endpoint
+
" HTTP/1.1
\r
"
+
"Host: "
+
host
+
"
\r
"
+
"Content-Type: text/plain
\r
"
+
"Content-Length: "
+
payload
.
length
()
+
"
\r\r
"
+
payload
;
espData
(
"AT+CIPMUX=1"
,
10
,
DEBUG
);
//Allow multiple connections
espData
(
"AT+CIPSTART=0,
\"
TCP
\"
,
\"
"
+
host
+
"
\"
,"
+
protocol
,
10
,
DEBUG
);
espData
(
"AT+CIPSEND=0,"
+
String
(
sendData
.
length
()
+
4
),
10
,
DEBUG
);
espSerial
.
find
(
'>'
);
String
response
=
espData
(
sendData
,
10
,
DEBUG
);
espData
(
"AT+CIPCLOSE=0"
,
10
,
DEBUG
);
return
response
;
}
String
SimulatedESP8266
::
espData
(
String
command
,
long
timeout
,
boolean
debug
)
{
String
response
=
""
;
espSerial
.
println
(
command
);
long
time
=
millis
();
while
((
time
+
timeout
)
>
millis
())
{
while
(
espSerial
.
available
())
{
char
c
=
espSerial
.
read
();
response
+=
c
;
}
}
return
response
;
}
This diff is collapsed.
Click to expand it.
Test/Test/src/SimulatedESP8266.h
0 → 100644
+
32
−
0
View file @
cd7cad0c
/**
* @file SimulatedESP8266.h
* @author Samuel Helbling (samuel.helbling@ost.ch)
* @brief
* @version 0.1
* @date 2021-04-29
*
* @copyright Copyright (c) 2021
**/
#include
"Arduino.h"
#include
<SoftwareSerial.h>
//Software Serial library
#ifndef SIMULATEDESP8266
#define SIMULATEDESP8266
class
SimulatedESP8266
{
public:
SimulatedESP8266
(
int
rxPin
,
int
txPin
);
void
setup
();
String
httpGet
(
String
host
,
String
endpoint
,
String
protocol
=
"80"
);
String
httpPost
(
String
host
,
String
endpoint
,
String
payload
,
String
protocol
=
"80"
);
private:
int
txPin
;
int
rxPin
;
String
espData
(
String
command
,
long
timeout
,
boolean
debug
);
SoftwareSerial
espSerial
=
SoftwareSerial
(
rxPin
,
txPin
);
};
#endif
This diff is collapsed.
Click to expand it.
Test/Test/src/main.cpp
+
19
−
0
View file @
cd7cad0c
#include
<Arduino.h>
#include
"AirSensor.h"
#include
"SimulatedESP8266.h"
int
ventilatorPinIN1
{
7
};
int
ventilatorPinIN2
{
6
};
...
...
@@ -11,6 +12,15 @@
const
float
thresholdVentilatorMax
{
0.6
};
float
airQuality
;
const
int
RX_PIN
{
11
};
const
int
TX_PIN
{
12
};
String
myHost
=
"104.248.41.20:1890"
;
SimulatedESP8266
simulatedESP8266
{
RX_PIN
,
TX_PIN
};
void
setup
()
{
pinMode
(
ventilatorPinEN
,
OUTPUT
);
pinMode
(
ventilatorPinIN1
,
OUTPUT
);
...
...
@@ -22,9 +32,13 @@ void setup() {
digitalWrite
(
ventilatorPinIN2
,
LOW
);
Serial
.
println
(
thresholdVentilatorMax
);
Serial
.
println
(
thresholdVentilatorStart
);
simulatedESP8266
.
setup
();
;
}
void
loop
()
{
airQuality
=
airSensor
.
getAirQuality
();
...
...
@@ -46,4 +60,9 @@ void loop() {
Serial
.
println
(
ventilatorSpeed
);
delay
(
500
);
String
payloadAirQuality
=
"{
\"
Luftqualität
\"
:"
+
String
(
airQuality
);
payloadAirQuality
=
payloadAirQuality
+
"}"
;
simulatedESP8266
.
httpPost
(
myHost
,
"/airQuality"
,
payloadAirQuality
);
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment