diff --git a/GW-custom/LoRa_homemade/config.py b/GW-custom/LoRa_homemade/config.py new file mode 100644 index 0000000000000000000000000000000000000000..fd6f75e288c1ea1dfa4d9651e341132a893ce229 --- /dev/null +++ b/GW-custom/LoRa_homemade/config.py @@ -0,0 +1,86 @@ +# Copyright 2020 LeMaRiva|tech lemariva.com +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +""" +# ES32 TTGO v1.0 +device_config = { + 'miso':19, + 'mosi':27, + 'ss':18, + 'sck':5, + 'dio_0':26, + 'reset':14, + 'led':2, +} + +# M5Stack ATOM Matrix +device_config = { + 'miso':23, + 'mosi':19, + 'ss':22, + 'sck':33, + 'dio_0':25, + 'reset':21, + 'led':12, +} +""" + +""" +#M5Stack & LoRA868 Module +device_config = { + 'miso':19, + 'mosi':23, + 'ss':5, + 'sck':18, + 'dio_0':26, + 'reset':36, + 'led':12, +} +""" + +# Configuration des broches pour le module LoRa E5 avec un ESP32 +device_config = { + 'miso': 19, # Pin MISO (Master In Slave Out) + 'mosi': 27, # Pin MOSI (Master Out Slave In) + 'ss': 18, # Pin SS (Chip Select) + 'sck': 5, # Pin SCK (Clock) + 'dio_0': 26, # Pin DIO0 (utilisé pour le mode interruption ou pour la détection de la fin de transmission) + 'reset': 14, # Pin RESET (si tu veux contrôler le reset du module) + 'led': 2, # Pin LED (si tu veux utiliser une LED pour indiquer l'état de l'appareil) +} + + +app_config = { + 'loop': 200, + 'sleep': 100, +} + +lora_parameters = { + 'frequency': 868E6, + 'tx_power_level': 2, + 'signal_bandwidth': 125E3, + 'spreading_factor': 12, + 'coding_rate': 5, + 'preamble_length': 8, + 'implicit_header': False, + 'sync_word': 0x12, + 'enable_CRC': False, + 'invert_IQ': False, +} + +wifi_config = { + 'ssid':'ObjetsConnectes', + 'password':'Pandemie2021' +} \ No newline at end of file diff --git a/GW-custom/LoRa_homemade/config_lora.py b/GW-custom/LoRa_homemade/config_lora.py new file mode 100644 index 0000000000000000000000000000000000000000..0112819183941f801049cff770b4c6945b445d67 --- /dev/null +++ b/GW-custom/LoRa_homemade/config_lora.py @@ -0,0 +1,18 @@ +import sys +import os +import time +import machine +import ubinascii + +def mac2eui(mac): + mac = mac[0:6] + 'fffe' + mac[6:] + return hex(int(mac[0:2], 16) ^ 2)[2:] + mac[2:] + +def get_millis(): + millisecond = time.ticks_ms() + return millisecond + +def get_nodename(): + uuid = ubinascii.hexlify(machine.unique_id()).decode() + node_name = "ESP_" + uuid + return node_name diff --git a/GW-custom/LoRa_homemade/main.py b/GW-custom/LoRa_homemade/main.py new file mode 100644 index 0000000000000000000000000000000000000000..1971f55a51518bfc7c8c1b8ec648a64fcd6bf40a --- /dev/null +++ b/GW-custom/LoRa_homemade/main.py @@ -0,0 +1,45 @@ +import time + +from machine import UART, Pin + +uart = UART(2, baudrate=9600, tx=17, rx=16) + +# Initialisation de la LED intégrée (souvent sur GPIO 2) +led = Pin(2, Pin.OUT) # GPIO 2 pour la LED intégrée + +def send_at_command(command): + uart.write((command + "\r\n").encode()) # Envoie la commande AT au module LoRa + time.sleep(0.3) # Attendre la réponse du module + while uart.any(): + response = uart.read().decode('utf-8') # Lire la réponse + print(response) + +def blink_led(times, interval): + for _ in range(times): + led.value(0) # Éteindre la LED + time.sleep(interval) # Attendre un certain temps + led.value(1) # Rallumer la LED + time.sleep(interval) # Attendre un certain temps + +# Initialisation du module LoRa +led.value(1) # Allumer la LED (rouge) +time.sleep(2) +print("Initialisation du module LoRa-E5...") +send_at_command("AT") +send_at_command("AT+MODE=TEST") +send_at_command("AT+DR=SF12BW125") # Définir le débit de données (ex: SF12BW125) +send_at_command("AT+TEST=RXLRPKT") # Commencer la réception des paquets LoRa + +print("Module LoRa-E5 initialisé. En attente de messages...") + +while True: + if uart.any(): # Si des données sont disponibles sur le port série + message = uart.read().decode('utf-8').strip() # Lire le message reçu + print(f"Message reçu : {message}") + + # Clignotement de la LED une fois pour indiquer la réception + led.value(0) # Éteindre la LED + time.sleep(0.1) # Attendre un peu + led.value(1) # Rallumer la LED + + time.sleep(0.01) # Petite pause pour éviter de saturer la boucle diff --git a/GW-custom/LoRa_homemade/pymakr.conf b/GW-custom/LoRa_homemade/pymakr.conf new file mode 100644 index 0000000000000000000000000000000000000000..08e4710f2ded1af4c9b02cdb363ce0636a36747c --- /dev/null +++ b/GW-custom/LoRa_homemade/pymakr.conf @@ -0,0 +1,23 @@ +{ + "address": "COM6", + "username": "micro", + "password": "python", + "open_on_start": true, + "safe_boot_on_upload": true, + "sync_file_types": "py", + "py_ignore": [ + "pymakr.conf", + "dev-requirements.txt", + ".vscode", + "LICENSE", + ".gitignore", + ".git", + "project.pymakr", + "env", + "venv", + ".python-version", + ".micropy/", + "micropy.json" + ], + "fast_upload": false +} \ No newline at end of file diff --git a/GW-custom/LoRa_homemade/sender.py b/GW-custom/LoRa_homemade/sender.py new file mode 100644 index 0000000000000000000000000000000000000000..ebae3ec042ad50d359fceb1fa03675ac7ab26f55 --- /dev/null +++ b/GW-custom/LoRa_homemade/sender.py @@ -0,0 +1,44 @@ +import time + +from machine import UART, Pin + +# Initialisation UART2 : TX=17, RX=16 +uart = UART(2, baudrate=9600, tx=17, rx=16, timeout=100) + +def send_at(cmd, wait=0.3): + full_cmd = cmd + '\r\n' + uart.write(full_cmd) + print(">>", cmd) + time.sleep(wait) + while uart.any(): + response = uart.readline() + if response: + print("<<", response.decode().strip()) + +def ascii_to_hex(s): + return ''.join(f'{ord(c):02X}' for c in s) + +# Initialisation du module LoRa-E5 en mode test +print("Initialisation du module LoRa-E5...") +send_at("AT") +send_at("AT+MODE=TEST") + +# Paramètres : fréquence, puissance, SF, BW +# Exemple : 868.1 MHz, puissance 14 dBm, SF12, BW 125 kHz +FREQ = "868100000" +POWER = "14" +SF = "12" +BW = "125" + +# Envoi en boucle +message_count = 1 + +while True: + text = f"MESSAGE {message_count}" + hex_payload = ascii_to_hex(text) + + at_cmd = f"AT+TEST=TXLRSTR,{FREQ},{POWER},{SF},{BW},{hex_payload}" + send_at(at_cmd) + + message_count += 1 + time.sleep(5) diff --git a/GW-custom/uPyLoRaWAN/sx127x.py b/GW-custom/uPyLoRaWAN/sx127x.py index 0fa6c17d6f8f97bbe9f77b7a013483f36688a4b9..fff86fae1fcfbf6c96bf871ad3d6e335c11a7095 100644 --- a/GW-custom/uPyLoRaWAN/sx127x.py +++ b/GW-custom/uPyLoRaWAN/sx127x.py @@ -1,6 +1,7 @@ +import gc from time import sleep + from machine import SPI, Pin -import gc PA_OUTPUT_RFO_PIN = 0 PA_OUTPUT_PA_BOOST_PIN = 1 @@ -118,6 +119,7 @@ class SX127x: if version != 0: init_try = False if version != 0x12: + print(version) raise Exception('Invalid version.') if __DEBUG__: