Skip to content

Commit

Permalink
Auto points example
Browse files Browse the repository at this point in the history
  • Loading branch information
FarrantAlex committed Dec 6, 2024
1 parent 3f66516 commit ce0eac5
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 0 deletions.
22 changes: 22 additions & 0 deletions python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -274,3 +274,25 @@ python3 CloudRF.py points \
--input-template ../templates/5G-CBand-sector.json \
--input-csv points.csv
```

### Auto Points

The below example shows a more advanced use of the `points` API which tests a spreadsheet of sites to a single receiver defined on the CLI. The output is then written to a new spreadsheet.

```bash
python3 autopoints.py --lat 38.91 --lon 1.43 --alt 12 \
-k xxxxxxxxxxxxxxxxxxxxxxxxxxxx \
-t ../templates/LoRa-GW-EU.json \
-i points.csv -o output.csv
```

The output looks like this:

```
Result:
server lat lon alt distance path_loss received_power
0 1 38.91338 1.438680 10 0.841 124.2 -104.2
1 2 38.91116 1.438119 10 0.715 129.4 -109.4
2 3 38.91073 1.442764 10 1.109 127.7 -107.7
3 4 38.91020 1.448539 10 1.606 141.1 -121.1
```
80 changes: 80 additions & 0 deletions python/autopoints.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@

import argparse
import json
import pandas
import requests

if __name__ == '__main__':

parser = argparse.ArgumentParser()

parser.add_argument("--lat", required = True, help = 'Receiever latitiude.')
parser.add_argument("--lon", required = True, help = 'Receiever longitude.')
parser.add_argument("--alt", required = True, help = 'Receiever altitude (m).')

parser.add_argument("-t", "--template-json", dest="template", required = True, help = 'Path to radio settings template json file.')

parser.add_argument("-k", "--api-key", dest="key", required=True, help = "cloudrf.com API key.")

parser.add_argument("-i", "--input-csv", dest="input", required = True, help = 'Path to input csv file containing transmitter positions. Expected headers are "lat", "lon", and "alt".')
parser.add_argument("-o", "--output-csv", dest="output", required = True, help = 'Path to output csv file, where results will be written.')

args = parser.parse_args()

print(f"Receiver latitiude: {args.lat}")
print(f"Receiver longitude: {args.lon}")
print(f"Receiver altitude: {args.alt}")

df = pandas.read_csv(args.input)

print(f"Transmitter count: {len(df.index)}")

with open(args.template) as template:
request = json.load(template)

request['receiver']['lat'] = args.lat
request['receiver']['lon'] = args.lon
request['receiver']['alt'] = args.alt

request['points'] = []

for index, row in df.iterrows():
request['points'].append({'lat': row.lat, 'lon': row.lon, 'alt': row.alt})

print("API Call:")
print()
print(json.dumps(request, indent = 4))
print()

response = requests.post(
url = "https://api.cloudrf.com/points",
headers = {
'key': args.key
},
json = request,
)

print(f"Response Code: {response.status_code}")

if response.status_code != 200:
print(f"Response body: {response.content}")
exit(1)

result = response.json()

print(f"Response:")
print()
print(json.dumps(result, indent = 4))
print()

output = []

for transmitter in result["Transmitters"]:
output.append({"server": transmitter["server"], "lat": transmitter["Latitude"], "lon": transmitter["Longitude"], "alt": transmitter["Antenna height m"], "distance": transmitter["Distance to receiver km"], "path_loss": transmitter["Computed path loss dB"],"received_power": transmitter["Signal power at receiver dBm"]})

output = pandas.DataFrame(output)

print("Result:")
print(output)

output.to_csv(args.output, index = False)

0 comments on commit ce0eac5

Please sign in to comment.