Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
MobileEventLog
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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Data-Logistics-Support
MobileEventLog
Commits
8ab7d38c
Commit
8ab7d38c
authored
2 years ago
by
Maximilian Betz
Browse files
Options
Downloads
Patches
Plain Diff
rasperry rest querry working
parent
e9b2850c
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
sw/lib/addeventkottaspegel.dart
+31
-12
31 additions, 12 deletions
sw/lib/addeventkottaspegel.dart
sw/lib/restdata.dart
+28
-0
28 additions, 0 deletions
sw/lib/restdata.dart
with
59 additions
and
12 deletions
sw/lib/addeventkottaspegel.dart
+
31
−
12
View file @
8ab7d38c
...
...
@@ -6,6 +6,7 @@ import 'datamodel.dart';
import
'databaseconnector.dart'
;
import
'dart:async'
;
import
'package:geolocator/geolocator.dart'
;
import
'restdata.dart'
;
class
AddEventKottasPegel
extends
StatefulWidget
{
const
AddEventKottasPegel
({
Key
?
key
})
:
super
(
key:
key
);
...
...
@@ -16,16 +17,20 @@ class AddEventKottasPegel extends StatefulWidget {
class
_AddEventKottasPegelPageState
extends
State
<
AddEventKottasPegel
>
{
RestData
restConnector
=
RestData
();
List
<
String
>
measurementStatusItems
=
[
'ok'
,
'broken'
,
'missing'
'tilted'
,];
List
<
String
>
angleStatusItems
=
[
'90° (straight)'
,
'80°'
,
'70°'
,
'60°'
,
'50°'
,
'40°'
,
'30°'
,
];
//Parameters which shall be added to the measurement event as json string data
String
measurementStatus
=
''
;
String
angleStatus
=
''
;
int
rawMeasurementValue
=
0
;
double
lengthOld
=
0.0
;
double
lengthNew
=
0.0
;
bool
syncGNSSData
=
true
;
bool
_addButtonEnabled
=
true
;
late
String
long
=
""
;
...
...
@@ -43,18 +48,34 @@ class _AddEventKottasPegelPageState extends State<AddEventKottasPegel> {
late
Timer
_overlayCloseTimer
;
Future
startRest
()
async
{
final
ConfigurationStoreInstance
configuration
=
ConfigurationStoreInstance
();
final
EventStoreInstance
event
=
EventStoreInstance
();
/* Function which starts querying the URL configuration.restRequestUrl */
restQueryTimer
=
Timer
.
periodic
(
const
Duration
(
seconds:
1
),
(
timer
)
{
// Querry Rest here
restQueryTimer
=
Timer
.
periodic
(
const
Duration
(
seconds:
1
),
(
timer
)
async
{
// Query data from raspberry pi here
try
{
Map
data
=
await
restConnector
.
fetchData
(
configuration
.
restRequestUrl
);
debugPrint
(
"Rest Query succeeded:
$data
"
);
event
.
currentEvent
.
latitude
=
data
[
'lat'
];
event
.
currentEvent
.
longitude
=
data
[
'lon'
];
event
.
currentEvent
.
startDate
=
data
[
'timestamp'
];
rawMeasurementValue
=
data
[
'length'
];
//in mm
accuracy
=
double
.
parse
(
data
[
'precision'
]
.
toString
());
//debugPrint("Rest Query succeeded: $data");
//{latPole: 70.66619463069793, lonPole: 8.291692251935759, timestamp: 2022/09/20 12:19:22 UTC, satsInView: 5}
}
catch
(
e
){
debugPrint
(
"Rest Query failed
$e
"
);
}
debugPrint
(
"Rest Querry.."
);
});
debugPrint
(
"left startRest"
);
}
);
}
Future
startGNSS
()
async
{
...
...
@@ -119,19 +140,17 @@ class _AddEventKottasPegelPageState extends State<AddEventKottasPegel> {
final
EventStoreInstance
event
=
EventStoreInstance
();
final
ConfigurationStoreInstance
configuration
=
ConfigurationStoreInstance
();
startGNSS
();
startGNSS
();
//Smartphones internal GNSS
//TODO: start async 1s rest poll to get length and position value from raspberries rest url
startRest
();
startRest
();
//To query data from raspberry Pi measurement
//Update current event with prefix and cnt
event
.
currentEvent
.
label
=
configuration
.
labelConfig
.
prefix
+
configuration
.
labelConfig
.
cnt
.
toString
();
//Set the device URN for the event fixed here! TODO: create device in sensor
and
add to a collection!
//event.currentEvent.urn
//Set the device URN for the event fixed here! TODO: create device in sensor
,
add to a collection!
//event.currentEvent.urn
TODO: set the urn here!
//event.currentEvent.urnId
super
.
initState
();
...
...
This diff is collapsed.
Click to expand it.
sw/lib/restdata.dart
+
28
−
0
View file @
8ab7d38c
import
'dart:async'
;
import
'dart:convert'
;
import
'dart:io'
;
import
'package:flutter/cupertino.dart'
;
...
...
@@ -5,3 +6,30 @@ import 'package:http/http.dart' as http;
import
'datamodel.dart'
;
class
RestData
{
Future
<
Map
>
fetchData
(
String
url
)
async
{
List
<
Collection
>
collectionList
=
[];
Map
valueMap
;
try
{
final
response
=
await
http
.
get
(
Uri
.
parse
(
url
))
.
timeout
(
const
Duration
(
milliseconds:
500
));
if
(
response
.
statusCode
==
200
)
{
valueMap
=
json
.
decode
(
response
.
body
)
;
return
valueMap
;
}
else
{
throw
Exception
(
'Failed to fetch Data. Header:
${response
.headers}
StatusCode:
${response.statusCode}
Body:
${response
.body}
'
);
}
}
on
SocketException
catch
(
e
)
{
throw
Exception
(
'No connection'
);
}
on
TimeoutException
catch
(
e
)
{
throw
Exception
(
'Connection Timeout'
);
}
catch
(
e
)
{
rethrow
;
}
}
}
\ 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