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
b9038bfc
Commit
b9038bfc
authored
Apr 21, 2020
by
Vladislav Rykov
Browse files
config acks tested
parent
d31eed3a
Changes
3
Show whitespace changes
Inline
Side-by-side
gateway
View file @
b9038bfc
No preview for this file type
postgre/gateway_db.sql
View file @
b9038bfc
...
@@ -45,8 +45,10 @@ ALTER TABLE esp32 OWNER TO pi;
...
@@ -45,8 +45,10 @@ ALTER TABLE esp32 OWNER TO pi;
--
--
CREATE
TABLE
pend_msgs
(
CREATE
TABLE
pend_msgs
(
app_key
VARCHAR
(
30
NOT
NULL
,
dev_id
numeric
(
3
,
0
)
NOT
NULL
,
dev_id
numeric
(
3
,
0
)
NOT
NULL
,
msg
bytea
msg
VARCHAR
(
150
),
ack
BOOLEAN
NOT
NULL
DEFAULT
FALSE
);
);
...
...
src/gateway.c
View file @
b9038bfc
...
@@ -190,7 +190,7 @@ int main (int argc, char **argv) {
...
@@ -190,7 +190,7 @@ int main (int argc, char **argv) {
fprintf
(
stderr
,
"payload decode error
\n
"
);
fprintf
(
stderr
,
"payload decode error
\n
"
);
}
}
}
else
if
(
packet_type
==
GATEWAY_PROTOCOL_PACKET_TYPE_PEND_REQ
)
{
}
else
if
(
packet_type
==
GATEWAY_PROTOCOL_PACKET_TYPE_PEND_REQ
)
{
sprintf
(
buf
,
"SELECT * FROM pend_msgs WHERE app_key = '%s' AND dev_id = %d"
,
sprintf
(
buf
,
"SELECT * FROM pend_msgs WHERE app_key = '%s' AND dev_id = %d
AND ack = False
"
,
(
char
*
)
gch
.
app_key
,
gch
.
dev_id
);
(
char
*
)
gch
.
app_key
,
gch
.
dev_id
);
res
=
PQexec
(
conn
,
buf
);
res
=
PQexec
(
conn
,
buf
);
if
(
PQresultStatus
(
res
)
==
PGRES_TUPLES_OK
&&
PQntuples
(
res
))
{
if
(
PQresultStatus
(
res
)
==
PGRES_TUPLES_OK
&&
PQntuples
(
res
))
{
...
@@ -232,7 +232,8 @@ int main (int argc, char **argv) {
...
@@ -232,7 +232,8 @@ int main (int argc, char **argv) {
buf_len
==
1
&&
buf_len
==
1
&&
buf
[
0
]
==
GATEWAY_PROTOCOL_STAT_ACK
)
buf
[
0
]
==
GATEWAY_PROTOCOL_STAT_ACK
)
{
{
sprintf
(
buf
,
"DELETE FROM pend_msgs WHERE app_key = '%s' AND dev_id = %d AND msg = '%s'"
,
(
char
*
)
gch
.
app_key
,
gch
.
dev_id
,
msg_cont
);
//sprintf(buf, "DELETE FROM pend_msgs WHERE app_key = '%s' AND dev_id = %d AND msg = '%s'", (char *)gch.app_key, gch.dev_id, msg_cont);
sprintf
(
buf
,
"UPDATE pend_msgs SET ack = True WHERE app_key = '%s' AND dev_id = %d AND msg = '%s'"
,
(
char
*
)
gch
.
app_key
,
gch
.
dev_id
,
msg_cont
);
printf
(
"%s"
,
buf
);
printf
(
"%s"
,
buf
);
res
=
PQexec
(
conn
,
buf
);
res
=
PQexec
(
conn
,
buf
);
if
(
PQresultStatus
(
res
)
!=
PGRES_COMMAND_OK
)
{
if
(
PQresultStatus
(
res
)
!=
PGRES_COMMAND_OK
)
{
...
...
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