Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions config_lora.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@
import ubinascii

def mac2eui(mac):
mac = mac[0:6] + 'fffe' + mac[6:]
return hex(int(mac[0:2], 16) ^ 2)[2:] + mac[2:]
mac = f'{mac[:6]}fffe{mac[6:]}'
return hex(int(mac[:2], 16) ^ 2)[2:] + mac[2:]
Comment on lines -8 to +9
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function mac2eui refactored with the following changes:


def get_millis():
millisecond = time.ticks_ms()
return millisecond
return time.ticks_ms()
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function get_millis refactored with the following changes:


def get_nodename():
uuid = ubinascii.hexlify(machine.unique_id()).decode()
node_name = "ESP_" + uuid
return node_name
return f"ESP_{uuid}"
Comment on lines -17 to +16
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function get_nodename refactored with the following changes:

2 changes: 1 addition & 1 deletion examples/LoRaReceiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ def receive(lora):
print('something here')
payload = lora.read_payload()
print(payload)
screen[0] = "pkt: {}".format(payload)
screen[0] = f"pkt: {payload}"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function receive refactored with the following changes:

write_screen(oled, screen)

6 changes: 3 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
example = 'receiver'

if __name__ == '__main__':
if example == 'sender':
LoRaSender.send(lora)
if example == 'receiver':
LoRaReceiver.receive(lora)
LoRaReceiver.receive(lora)
elif example == 'sender':
LoRaSender.send(lora)
2 changes: 1 addition & 1 deletion oled.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def init_oled():
def write_screen(oled, screen):
oled.fill(0)
for row, text in enumerate(screen):
print("{} - {}".format(row, text))
print(f"{row} - {text}")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function write_screen refactored with the following changes:

line = 12 * row
oled.text(text, 0, line, 1)
oled.show()
Expand Down
16 changes: 8 additions & 8 deletions sx127x.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,14 @@ def __init__(self,
re_try = 0
while init_try and re_try < 5:
version = self.read_register(REG_VERSION)
re_try = re_try + 1
re_try += 1
if version != 0:
init_try = False
#if version != 0x12:
# raise Exception('Invalid version.')

if __DEBUG__:
print("SX version: {}".format(version))
print(f"SX version: {version}")
Comment on lines -117 to +124
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function SX127x.__init__ refactored with the following changes:


# put in LoRa and sleep mode
self.sleep()
Expand Down Expand Up @@ -252,7 +252,7 @@ def set_tx_power(self, level, outputPin = PA_OUTPUT_PA_BOOST_PIN):
def set_frequency(self, frequency):
self._frequency = frequency

freq_reg = int(int(int(frequency) << 19) / 32000000) & 0xFFFFFF
freq_reg = int(int(frequency) << 19) // 32000000 & 0xFFFFFF
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function SX127x.set_frequency refactored with the following changes:


self.write_register(REG_FRF_MSB, (freq_reg & 0xFF0000) >> 16)
self.write_register(REG_FRF_MID, (freq_reg & 0xFF00) >> 8)
Expand All @@ -268,13 +268,13 @@ def set_spreading_factor(self, sf):
)

def set_signal_bandwidth(self, sbw):
bins = (7.8E3, 10.4E3, 15.6E3, 20.8E3, 31.25E3, 41.7E3, 62.5E3, 125E3, 250E3)

bw = 9

if sbw < 10:
bw = sbw
else:
bins = (7.8E3, 10.4E3, 15.6E3, 20.8E3, 31.25E3, 41.7E3, 62.5E3, 125E3, 250E3)

Comment on lines -271 to +277
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function SX127x.set_signal_bandwidth refactored with the following changes:

for i in range(len(bins)):
if sbw <= bins[i]:
bw = i
Expand Down Expand Up @@ -453,7 +453,7 @@ def read_payload(self):
packet_length = self.read_register(REG_RX_NB_BYTES)

payload = bytearray()
for i in range(packet_length):
for _ in range(packet_length):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function SX127x.read_payload refactored with the following changes:

payload.append(self.read_register(REG_FIFO))

self.collect_garbage()
Expand All @@ -480,7 +480,7 @@ def transfer(self, address, value = 0x00):
return response

def blink_led(self, times = 1, on_seconds = 0.1, off_seconds = 0.1):
for i in range(times):
for _ in range(times):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function SX127x.blink_led refactored with the following changes:

if self._led_status:
self._led_status.value(True)
sleep(on_seconds)
Expand All @@ -490,4 +490,4 @@ def blink_led(self, times = 1, on_seconds = 0.1, off_seconds = 0.1):
def collect_garbage(self):
gc.collect()
if __DEBUG__:
print('[Memory - free: {} allocated: {}]'.format(gc.mem_free(), gc.mem_alloc()))
print(f'[Memory - free: {gc.mem_free()} allocated: {gc.mem_alloc()}]')
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function SX127x.collect_garbage refactored with the following changes: