Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Vladislav Rykov
THSO.gateway
Commits
c26be7a7
Commit
c26be7a7
authored
Mar 30, 2020
by
Vladislav Rykov
Browse files
stat mngmt added
parent
6cf62525
Changes
2
Hide whitespace changes
Inline
Side-by-side
gateway
View file @
c26be7a7
No preview for this file type
src/gateway.c
View file @
c26be7a7
...
@@ -126,46 +126,66 @@ int main (int argc, char **argv) {
...
@@ -126,46 +126,66 @@ int main (int argc, char **argv) {
if
(
gateway_protocol_data_send_payload_decode
(
&
sensor_data
,
payload
,
payload_length
))
{
if
(
gateway_protocol_data_send_payload_decode
(
&
sensor_data
,
payload
,
payload_length
))
{
PGresult
*
res
;
PGresult
*
res
;
snprintf
(
buf
,
sizeof
(
buf
),
"INSERT INTO esp32 VALUES("
snprintf
(
buf
,
sizeof
(
buf
),
"INSERT INTO esp32 VALUES("
"%lu, '%s', "
"%lu, '%s', "
"%.2f, %.2f, "
// esp
"%.2f, %.2f, "
// esp
"%.2f, %.2f, "
"%.2f, %.2f, "
"%.2f, %.2f, "
"%.2f, %.2f, "
"%.2f, %.2f, %.2f, "
"%.2f, %.2f, %.2f, "
"%.2f, "
"%.2f, "
"%.2f, "
"%.2f, "
"%.2f, %.2f, "
// mkr
"%.2f, %.2f, "
// mkr
"%.2f, %.2f, "
"%.2f, %.2f, "
"%.2f, %.2f, "
"%.2f, %.2f, "
"%.2f, "
"%.2f, "
"%.2f, %.2f, "
// wis
"%.2f, %.2f, "
// wis
"%.2f, %.2f, "
"%.2f, %.2f, "
"%.2f, %.2f, "
"%.2f, %.2f, "
"%.2f, "
"%.2f, "
"%.2f)"
,
"%.2f)"
,
sensor_data
.
utc
,
sensor_data
.
timedate
,
sensor_data
.
utc
,
sensor_data
.
timedate
,
sensor_data
.
dht22_t_esp
,
sensor_data
.
dht22_h_esp
,
sensor_data
.
dht22_t_esp
,
sensor_data
.
dht22_h_esp
,
sensor_data
.
sht85_t_esp
,
sensor_data
.
sht85_h_esp
,
sensor_data
.
sht85_t_esp
,
sensor_data
.
sht85_h_esp
,
sensor_data
.
hih8121_t_esp
,
sensor_data
.
hih8121_h_esp
,
sensor_data
.
hih8121_t_esp
,
sensor_data
.
hih8121_h_esp
,
sensor_data
.
tmp36_0_esp
,
sensor_data
.
tmp36_1_esp
,
sensor_data
.
tmp36_2_esp
,
sensor_data
.
tmp36_0_esp
,
sensor_data
.
tmp36_1_esp
,
sensor_data
.
tmp36_2_esp
,
sensor_data
.
hih4030_esp
,
sensor_data
.
hih4030_esp
,
sensor_data
.
hh10d_esp
,
sensor_data
.
hh10d_esp
,
sensor_data
.
dht22_t_mkr
,
sensor_data
.
dht22_h_mkr
,
sensor_data
.
dht22_t_mkr
,
sensor_data
.
dht22_h_mkr
,
sensor_data
.
sht85_t_mkr
,
sensor_data
.
sht85_h_mkr
,
sensor_data
.
sht85_t_mkr
,
sensor_data
.
sht85_h_mkr
,
sensor_data
.
hih8121_t_mkr
,
sensor_data
.
hih8121_h_mkr
,
sensor_data
.
hih8121_t_mkr
,
sensor_data
.
hih8121_h_mkr
,
sensor_data
.
hh10d_mkr
,
sensor_data
.
hh10d_mkr
,
sensor_data
.
dht22_t_wis
,
sensor_data
.
dht22_h_wis
,
sensor_data
.
dht22_t_wis
,
sensor_data
.
dht22_h_wis
,
sensor_data
.
sht85_t_wis
,
sensor_data
.
sht85_h_wis
,
sensor_data
.
sht85_t_wis
,
sensor_data
.
sht85_h_wis
,
sensor_data
.
hih8121_t_wis
,
sensor_data
.
hih8121_h_wis
,
sensor_data
.
hih8121_t_wis
,
sensor_data
.
hih8121_h_wis
,
sensor_data
.
tmp102_wis
,
sensor_data
.
tmp102_wis
,
sensor_data
.
hh10d_wis
sensor_data
.
hh10d_wis
);
);
//printf("%s\n", buf);
//printf("%s\n", buf);
res
=
PQexec
(
conn
,
buf
);
res
=
PQexec
(
conn
,
buf
);
if
(
PQresultStatus
(
res
)
!=
PGRES_COMMAND_OK
)
{
if
(
PQresultStatus
(
res
)
==
PGRES_COMMAND_OK
)
{
PQclear
(
res
);
fprintf
(
stderr
,
"%s
\n
"
,
PQerrorMessage
(
conn
));
fprintf
(
stderr
,
"%s
\n
"
,
PQerrorMessage
(
conn
));
sprintf
(
buf
,
"SELECT * FROM pend_msgs WHERE dev_id = %d"
,
dev_id
);
res
=
PQexec
(
conn
,
buf
);
if
(
PQresultStatus
(
res
)
==
PGRES_TUPLES_OK
&&
PQntuples
(
res
))
{
buf
[
2
]
=
GATEWAY_PROTOCOL_STAT_ACK_PEND
;
printf
(
"ACK_PEND prepared
\n
"
);
}
else
{
buf
[
2
]
=
GATEWAY_PROTOCOL_STAT_ACK
;
printf
(
"ACK prepared
\n
"
);
}
buf
[
0
]
=
dev_id
;
buf
[
1
]
=
GATEWAY_PROTOCOL_PACKET_TYPE_STAT
;
buf_len
=
3
;
}
}
PQclear
(
res
);
PQclear
(
res
);
}
else
{
}
else
{
buf
[
0
]
=
dev_id
;
buf
[
1
]
=
GATEWAY_PROTOCOL_PACKET_TYPE_STAT
;
buf
[
2
]
=
GATEWAY_PROTOCOL_STAT_NACK
;
buf_len
=
3
;
printf
(
"payload decode error
\n
"
);
printf
(
"payload decode error
\n
"
);
}
}
}
else
if
(
packet_type
==
GATEWAY_PROTOCOL_PACKET_TYPE_PEND_REQ
)
{
}
else
if
(
packet_type
==
GATEWAY_PROTOCOL_PACKET_TYPE_PEND_REQ
)
{
...
...
Write
Preview
Supports
Markdown
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