Enthernet Code
Enthernet Code
DIIDevHeads IoT Integration Server
Created by Enthernet Code on 7/11/2024 in #edge-networking
How can I achieve reliable data transfer over LoRa using MicroPython on Pycom GPy?
Hello guys, after a while of debugging and checking through I was able to fix the ValueError: invalid pin for ADC on my code, it turns out I was required to use p15 intead of p13 and for the Not joined yet... error it was due to tge mistake I made in imputing my Appkey which i have corrected now. This is My. Code
from machine import Pin, ADC
from network import LoRa
import socket
import time

# Initialize soil moisture sensor
adc = ADC() # Corrected ADC initialization
moisture_pin = adc.channel(attn=ADC.ATTN_11DB, pin='P15') # Corrected pin configuration

# Initialize LoRa
lora = LoRa(mode=LoRa.LORAWAN, region=LoRa.EU868)
lora_sock = socket.socket(socket.AF_LORA, socket.SOCK_RAW)
lora_sock.setblocking(False)

# LoRa OTAA credentials
dev_eui = '********'
DevEUI
app_eui = '********'
AppEUI
app_key = '********'
AppKey

# Join the network
lora.join(activation=LoRa.OTAA, auth=(dev_eui, app_eui, app_key), timeout=0)

# Wait until the module has joined the network
while not lora.has_joined():
time.sleep(2.5)
print('Not joined yet...')

print('Joined the network!')

# Function to read soil moisture
def read_soil_moisture():
moisture = moisture_pin.voltage() # Use voltage method to get the sensor reading
print('Soil moisture:', moisture)
return moisture

while True:
# Read sensor data
soil_moisture = read_soil_moisture()

# Prepare data for transmission
data = [int(soil_moisture / 4)]

# Send data via LoRa
lora_sock.send(data)
print('Data sent:', soil_moisture)

# Sleep for a while
time.sleep(60)
from machine import Pin, ADC
from network import LoRa
import socket
import time

# Initialize soil moisture sensor
adc = ADC() # Corrected ADC initialization
moisture_pin = adc.channel(attn=ADC.ATTN_11DB, pin='P15') # Corrected pin configuration

# Initialize LoRa
lora = LoRa(mode=LoRa.LORAWAN, region=LoRa.EU868)
lora_sock = socket.socket(socket.AF_LORA, socket.SOCK_RAW)
lora_sock.setblocking(False)

# LoRa OTAA credentials
dev_eui = '********'
DevEUI
app_eui = '********'
AppEUI
app_key = '********'
AppKey

# Join the network
lora.join(activation=LoRa.OTAA, auth=(dev_eui, app_eui, app_key), timeout=0)

# Wait until the module has joined the network
while not lora.has_joined():
time.sleep(2.5)
print('Not joined yet...')

print('Joined the network!')

# Function to read soil moisture
def read_soil_moisture():
moisture = moisture_pin.voltage() # Use voltage method to get the sensor reading
print('Soil moisture:', moisture)
return moisture

while True:
# Read sensor data
soil_moisture = read_soil_moisture()

# Prepare data for transmission
data = [int(soil_moisture / 4)]

# Send data via LoRa
lora_sock.send(data)
print('Data sent:', soil_moisture)

# Sleep for a while
time.sleep(60)
6 replies