Skip to content

Commit

Permalink
added list devices
Browse files Browse the repository at this point in the history
  • Loading branch information
akhenakh committed Nov 23, 2019
1 parent b8d20b9 commit 89b7db4
Show file tree
Hide file tree
Showing 12 changed files with 279 additions and 62 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ service GeoTTN {
rpc RectSearch(RectSearchRequest) returns (DataPoints) {}
rpc Get(GetRequest) returns (DataPoint) {}
rpc GetAll(GetRequest) returns (DataPoints) {}
rpc Keys(google.protobuf.Empty) returns (KeyList) {}
}
```

Expand All @@ -83,6 +84,7 @@ There is a demo cli in `cmd/geottncli`

A very simple web API (used for the web interface):
```go
r.HandleFunc("/api/devices", s.DevicesQuery)
r.HandleFunc("/api/data/{key}", s.DataQuery)
r.HandleFunc("/api/rect/{urlat}/{urlng}/{bllat}/{bllng}", s.RectQuery)
```
Expand Down
2 changes: 1 addition & 1 deletion cmd/createpayload/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func main() {

e := cayenne.NewEncoder()
e.AddGPS(uint8(*channel), float32(*lat), float32(*lng), 0.0)

e.AddTemperature(uint8(*channel+1), -3)
b := e.Bytes()
hexPayload := hex.EncodeToString(b)
fmt.Println("Data", hexPayload)
Expand Down
1 change: 1 addition & 0 deletions cmd/geottnd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ func main() {
s.Box = box

r := mux.NewRouter()
r.HandleFunc("/api/devices", s.DevicesQuery)
r.HandleFunc("/api/data/{key}", s.DataQuery)
r.HandleFunc("/api/rect/{urlat}/{urlng}/{bllat}/{bllng}", s.RectQuery)
r.PathPrefix("/").Handler(
Expand Down
64 changes: 44 additions & 20 deletions cmd/geottnd/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,32 @@
<body>
<div class="container">
<div class="row">
<div class="col">
<div id='map'></div>
<div class="col-2">
<ul class="list-group list-group-flush" id="devices_list">

</ul>
</div>
</div>
<div class="row">
<div class="col">
<dl class="row">
<dt class="col-sm-3">Device</dt>
<dd class="col-sm-9" id="device_id">No device selected</dd>
</dl>
<table class="table table-striped">
<thead>
<tr>
<th scope="col">Time</th>
<th scope="col">Values</th>
</tr>
</thead>
<tbody id='device_body'>

</tbody>
</table>
<div class="col-10">
<div id='map'></div>
<div class="row">
<div class="col">
<dl class="row">
<dt class="col-sm-3">Device</dt>
<dd class="col-sm-9" id="device_id">No device selected</dd>
</dl>
<table class="table table-striped">
<thead>
<tr>
<th scope="col">Time</th>
<th scope="col">Values</th>
</tr>
</thead>
<tbody id='device_body'>

</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
Expand Down Expand Up @@ -98,6 +103,7 @@
"/" + mapBounds.getSouthWest().lat + "/" + mapBounds.getSouthWest().lng;
}
map.on('load', function () {

map.addSource('points', { type: 'geojson', data: urlForBounds() });
map.addLayer({
"id": "points",
Expand All @@ -115,6 +121,24 @@
"text-radial-offset": 0.6,
}
});

const xhr = new XMLHttpRequest();
xhr.open('GET', "/api/devices", true);
xhr.onload = function() {
if (xhr.status !== 200) {
return;
}
let data = JSON.parse(xhr.responseText);

const devicelist = document.getElementById('devices_list');
devicelist.innerHTML = '<li class="list-group-item">Devices List</li>';

data.forEach(function (value) {
devicelist.innerHTML += `<li class="list-group-item"><button type="button" class="btn btn-link">` + value + `</button></li>`;
});

};
xhr.send();
});
map.on('click', 'points', function (e) {
const key = e.features[0].properties.device_id;
Expand Down
146 changes: 110 additions & 36 deletions geottnsvc/geottnsvc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions geottnsvc/geottnsvc.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ service GeoTTN {
rpc RectSearch(RectSearchRequest) returns (DataPoints) {}
rpc Get(GetRequest) returns (DataPoint) {}
rpc GetAll(GetRequest) returns (DataPoints) {}
rpc Keys(google.protobuf.Empty) returns (KeyList) {}
}

message DataPoint {
Expand All @@ -20,6 +21,10 @@ message DataPoint {
bytes payload = 6;
}

message KeyList {
repeated string keys = 1;
}

message DataPoints {
repeated DataPoint points = 1;
}
Expand Down
9 changes: 9 additions & 0 deletions geottnsvc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,15 @@ func (s *Server) Get(ctx context.Context, req *GetRequest) (*DataPoint, error) {
return StorageToDataPoint(dps), nil
}

func (s *Server) Keys(context.Context, *empty.Empty) (*KeyList, error) {
keys, err := s.GeoDB.Keys()
if err != nil {
return nil, err
}

return &KeyList{Keys: keys}, nil
}

func (s *Server) GetAll(ctx context.Context, in *GetRequest) (*DataPoints, error) {
return nil, errors.New("not implemented")
}
Expand Down
Binary file modified img/interface.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 89b7db4

Please sign in to comment.