Close

Making Data Available for Transmission in Python

A project log for LoRa + Neural Network Security System

Spot trespassers with a neural network and transmit basic results via LoRa

capt-flatus-oflahertyCapt. Flatus O'Flaherty ☠ 12/07/2018 at 22:330 Comments

I've not programmed in Python before, but compared to C++ it already seems much easier and a lot more intuitive.

I worked out that the Lora beacon was the probably right place to start tinkering and that it needed a 'list' of numbers that represent ANSII characters and that these can be decimal or hex values. The actual phrase in the beacon program that transmits the data is on line 65:

self.write_payload(j)

where j is the payload list, which would normally look something like this for 'Hello World':

([72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100])

 To get 'Hello World' into this list format the following code is used:

import array as arr
import numpy as np

c= 'Hello World'
g = arr.array('i',[])
n=-1

for x in c: g.extend([0]) n = n+1 y = ord(x) g[n] = y
print(g)

j = np.array(g).tolist()

The code converts each of the characters in the string to an integer in an integer array, denoted by the letter 'i', of length c, corresponding to the number of characters and spaces in the string. The extend command extends the array to accept more integers. Next, for each of the characters in the string the 'ord' command does the actual character to integer transformation and 'g[n] = y' dumps it into the right place in the array. Last is the array to list command that turns the whole array into the list format. Simples! 

The new LoRa beacon file is called Tegwyns_LoRa_Beacon in the files section of this blog and, assuming it's located in the same place as the original beacon file, it would be run from the command line with:

cd /home/pi/Desktop/dragonino_python_fix/pySX127x-master/ && python3 Tegwyns_LoRa_Beacon.py -f 869 -s 7

Discussions