LoRaWAN - RAK WIRELESS

Place code snippets and demo code here
User avatar
cicciocb
Site Admin
Posts: 1997
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 428 times
Been thanked: 1336 times
Contact:

Re: LoRaWAN - RAK WIRELESS

Post by cicciocb »

Hi Miguel,
I did an update on the ESP32, you can download the latest version 1.51.6 that contains a "patch / fix" for this problem.

Try it and let me know
tcpipchip
Posts: 76
Joined: Fri Apr 02, 2021 12:48 am
Been thanked: 59 times

Re: LoRaWAN - RAK WIRELESS

Post by tcpipchip »

Code: [Local Link Removed for Guests]

rem joined status
pin.mode 2, output 
rem relay 1
pin.mode 23, output
rem relay 1
pin.mode 19, output
rem relay 1
pin.mode 18, output
rem relay 1
pin.mode 5, output

rem relay off
pin(23) = 0
pin(19) = 0
pin(18) = 0
pin(5) = 0

serial2.mode 115200, 13, 15
onserial2 rec2
rem wait

BOOT:
ERRORS_LINKCHECK=0
JOINED$="NO"
FAIL$="NO"

pin(2) = 0
rem Pause enough to receive the JOIN
PAUSE 20000

if JOINED$="YES" then
   goto GOT_JOINED
end if

rem enable LoRaWAN
print2 "AT+NWM=1" + CHR$(13) + CHR$(10)
PAUSE 500

rem enable linkcheck message
print2 "AT+LINKCHECK=2" + CHR$(13) + CHR$(10)
PAUSE 500

rem DEV EUI
print2 "AT+DEVEUI=0080e115051fd80a" + CHR$(13) + CHR$(10)
PAUSE 500

rem APP KEY
print2 "AT+APPKEY=a614d59963a0861edf2702ae6f0e1ad6" + CHR$(13) + CHR$(10)
PAUSE 500

rem AU915
print2 "AT+BAND=6" + CHR$(13) + CHR$(10)
PAUSE 500

rem MASK (regional parameters)
print2 "AT+MASK=0002" + CHR$(13) + CHR$(10)
PAUSE 500

rem CLASS A
print2 "AT+CLASS=A" + CHR$(13) + CHR$(10)
PAUSE 500

rem no confirmation downlink
print2 "AT+CFM=0" + CHR$(13) + CHR$(10)
PAUSE 500

rem TX POWER 14
print2 "AT+TXP=14" + CHR$(13) + CHR$(10)
PAUSE 500

rem adaptative data rate
print2 "AT+ADR=1" + CHR$(13) + CHR$(10)
PAUSE 500

rem private network
print2 "AT+PNM=1" + CHR$(13) + CHR$(10)
PAUSE 500

rem auto join
print2 "AT+JOIN=1:0:10:8" + CHR$(13) + CHR$(10)
PAUSE 500

GOT_JOINED:

while 1=1
  print2 "AT+NJS=?" + CHR$(13) + CHR$(10)
  PAUSE 10000
  IF JOINED$="YES" THEN
    pin(2) = 1
    FAIL$="NO"
    print "Sending Package"
    print2 "AT+MASK=0002" + CHR$(13) + CHR$(10)
    PAUSE 500
    print2 "AT+SEND=2:AAAAAAAA" + CHR$(13) + CHR$(10)
    PAUSE 500
  END IF
  if FAIL$ = "YES" then GOTO BOOT
 wend

rec2:
r$ = serial2.input$
print r$
if INSTR(1, r$, "JOINED")>0 then
  if INSTR(1, r$, "AT_NO_NETWORK_JOINED")>0 then
    FAIL$="YES"
    JOINED$="FALSE"
    GOTO sai_serial2
  else
    PRINT "CONGRATULATIONS, JOINED"
    JOINED$="YES"
    GOTO sai_serial2
  end if
end if
if INSTR(1, r$, "AT+NJS=0")>0 then
  FAIL$="YES"
  JOINED$="FALSE"
  GOTO sai_serial2    
end if
if INSTR(1, r$, "+EVT:SEND_CONFIRMED_FAILED")>0 then
  FAIL$="YES"
  JOINED$="FALSE"
  GOTO sai_serial2    
end if
if INSTR(1, r$, "+EVT:JOIN_FAILED_RX_TIMEOUT")>0 then
  FAIL$="YES"
  JOINED$="FALSE"
  GOTO sai_serial2    
end if
rem downlink
rem +EVT:RX_1:-67:8:UNICAST:4:30303030313131
rem +EVT:LINKCHECK:0:24:1:-67:8
if INSTR(1, r$, "+EVT:RX_1")>0 then
  s$= mid$(r$, INSTR(1, r$, ":")+1)
  s$= mid$(s$, INSTR(1, s$, ":")+1)
  s$= mid$(s$, INSTR(1, s$, ":")+1)
  s$= mid$(s$, INSTR(1, s$, ":")+1)
  s$= mid$(s$, INSTR(1, s$, ":")+1)
  s$= mid$(s$, INSTR(1, s$, ":")+1)
  s$= left$(s$, INSTR(1, s$, "+EVT")-1)
  if INSTR(1, s$, "31")>0 then
    pin(23) = 1  
    GOTO sai_serial2
  end if
  if INSTR(1, s$, "32")>0 then
    pin(19) = 1  
    GOTO sai_serial2
  end if
  if INSTR(1, s$, "33")>0 then
    pin(18) = 1  
    GOTO sai_serial2
  end if
  if INSTR(1, s$, "34")>0 then
    pin(5) = 1  
    GOTO sai_serial2
  end if  
  if INSTR(1, s$, "35")>0 then
    pin(23) = 0  
    GOTO sai_serial2
  end if
  if INSTR(1, s$, "36")>0 then
    pin(19) = 0  
    GOTO sai_serial2
  end if
  if INSTR(1, s$, "37")>0 then
    pin(18) = 0  
    GOTO sai_serial2
  end if
  if INSTR(1, s$, "38")>0 then
    pin(5) = 0 
    GOTO sai_serial2
  end if  
  GOTO sai_serial2    
end if
if INSTR(1, r$, "AT_PARAM_ERROR")>0 then
end if
if INSTR(1, r$, "+EVT:LINKCHECK")>0 then
  if INSTR(1, r$, "+EVT:LINKCHECK:1:0:0:0:0")>0 then
    ERRORS_LINKCHECK=ERRORS_LINKCHECK+1
    if ERRORS_LINKCHECK=3 THEN
      ERRORS_LINKCHECK=0
      FAIL$="YES"
      JOINED$="FALSE"
      GOTO sai_serial2    
    end if
  else
    print "Package Sent"
    ERRORS_LINKCHECK=0
    GOTO sai_serial2    
  end if
end if
sai_serial2:
return
I still having the same ENDIF error...
ENDIF without IF line 96
tcpipchip
Posts: 76
Joined: Fri Apr 02, 2021 12:48 am
Been thanked: 59 times

Re: LoRaWAN - RAK WIRELESS

Post by tcpipchip »

to bypass, i had to do

Code: [Local Link Removed for Guests]

rem joined status
pin.mode 2, output 
rem relay 1
pin.mode 23, output
rem relay 1
pin.mode 19, output
rem relay 1
pin.mode 18, output
rem relay 1
pin.mode 5, output

rem relay off
pin(23) = 0
pin(19) = 0
pin(18) = 0
pin(5) = 0

serial2.mode 115200, 13, 15
onserial2 rec2
rem wait

BOOT:
ERRORS_LINKCHECK=0
JOINED$="NO"
FAIL$="NO"

pin(2) = 0
rem Pause enough to receive the JOIN
PAUSE 20000

if JOINED$="YES" then
   goto GOT_JOINED
end if

rem enable LoRaWAN
print2 "AT+NWM=1" + CHR$(13) + CHR$(10)
PAUSE 500

rem enable linkcheck message
print2 "AT+LINKCHECK=2" + CHR$(13) + CHR$(10)
PAUSE 500

rem DEV EUI
print2 "AT+DEVEUI=0080e115051fd80a" + CHR$(13) + CHR$(10)
PAUSE 500

rem APP KEY
print2 "AT+APPKEY=a614d59963a0861edf2702ae6f0e1ad6" + CHR$(13) + CHR$(10)
PAUSE 500

rem AU915
print2 "AT+BAND=6" + CHR$(13) + CHR$(10)
PAUSE 500

rem MASK (regional parameters)
print2 "AT+MASK=0002" + CHR$(13) + CHR$(10)
PAUSE 500

rem CLASS A
print2 "AT+CLASS=A" + CHR$(13) + CHR$(10)
PAUSE 500

rem no confirmation downlink
print2 "AT+CFM=0" + CHR$(13) + CHR$(10)
PAUSE 500

rem TX POWER 14
print2 "AT+TXP=14" + CHR$(13) + CHR$(10)
PAUSE 500

rem adaptative data rate
print2 "AT+ADR=1" + CHR$(13) + CHR$(10)
PAUSE 500

rem private network
print2 "AT+PNM=1" + CHR$(13) + CHR$(10)
PAUSE 500

rem auto join
print2 "AT+JOIN=1:0:10:8" + CHR$(13) + CHR$(10)
PAUSE 500

GOT_JOINED:

while 1=1
  print2 "AT+NJS=?" + CHR$(13) + CHR$(10)
  PAUSE 10000
  rem ============================================================
  IF JOINED$="YES" THEN GOSUB SEND_PACKAGE
  rem ============================================================
  if FAIL$ = "YES" then GOTO BOOT
 wend

rec2:
r$ = serial2.input$
print r$
if INSTR(1, r$, "JOINED")>0 then
  if INSTR(1, r$, "AT_NO_NETWORK_JOINED")>0 then
    FAIL$="YES"
    JOINED$="FALSE"
    GOTO sai_serial2
  else
    PRINT "CONGRATULATIONS, JOINED"
    JOINED$="YES"
    GOTO sai_serial2
  end if
end if
if INSTR(1, r$, "AT+NJS=0")>0 then
  FAIL$="YES"
  JOINED$="FALSE"
  GOTO sai_serial2    
end if
if INSTR(1, r$, "+EVT:SEND_CONFIRMED_FAILED")>0 then
  FAIL$="YES"
  JOINED$="FALSE"
  GOTO sai_serial2    
end if
if INSTR(1, r$, "+EVT:JOIN_FAILED_RX_TIMEOUT")>0 then
  FAIL$="YES"
  JOINED$="FALSE"
  GOTO sai_serial2    
end if
rem downlink
rem +EVT:RX_1:-67:8:UNICAST:4:30303030313131
rem +EVT:LINKCHECK:0:24:1:-67:8
if INSTR(1, r$, "+EVT:RX_1")>0 then
  s$= mid$(r$, INSTR(1, r$, ":")+1)
  s$= mid$(s$, INSTR(1, s$, ":")+1)
  s$= mid$(s$, INSTR(1, s$, ":")+1)
  s$= mid$(s$, INSTR(1, s$, ":")+1)
  s$= mid$(s$, INSTR(1, s$, ":")+1)
  s$= mid$(s$, INSTR(1, s$, ":")+1)
  s$= left$(s$, INSTR(1, s$, "+EVT")-1)
  if INSTR(1, s$, "31")>0 then
    pin(23) = 1  
    GOTO sai_serial2
  end if
  if INSTR(1, s$, "32")>0 then
    pin(19) = 1  
    GOTO sai_serial2
  end if
  if INSTR(1, s$, "33")>0 then
    pin(18) = 1  
    GOTO sai_serial2
  end if
  if INSTR(1, s$, "34")>0 then
    pin(5) = 1  
    GOTO sai_serial2
  end if  
  if INSTR(1, s$, "35")>0 then
    pin(23) = 0  
    GOTO sai_serial2
  end if
  if INSTR(1, s$, "36")>0 then
    pin(19) = 0  
    GOTO sai_serial2
  end if
  if INSTR(1, s$, "37")>0 then
    pin(18) = 0  
    GOTO sai_serial2
  end if
  if INSTR(1, s$, "38")>0 then
    pin(5) = 0 
    GOTO sai_serial2
  end if  
  GOTO sai_serial2    
end if
if INSTR(1, r$, "AT_PARAM_ERROR")>0 then
end if
if INSTR(1, r$, "+EVT:LINKCHECK")>0 then
  if INSTR(1, r$, "+EVT:LINKCHECK:1:0:0:0:0")>0 then
    ERRORS_LINKCHECK=ERRORS_LINKCHECK+1
    if ERRORS_LINKCHECK=3 THEN
      ERRORS_LINKCHECK=0
      FAIL$="YES"
      JOINED$="FALSE"
      GOTO sai_serial2    
    end if
  else
    print "Package Sent"
    ERRORS_LINKCHECK=0
    GOTO sai_serial2    
  end if
end if
sai_serial2:
return

    rem ============================================================
SEND_PACKAGE:
    pin(2) = 1
    FAIL$="NO"
    print "Sending Package"
    print2 "AT+MASK=0002" + CHR$(13) + CHR$(10)
    PAUSE 500
    print2 "AT+SEND=2:AAAAAAAA" + CHR$(13) + CHR$(10)
    PAUSE 500
    RETURN
    rem ============================================================
tcpipchip
Posts: 76
Joined: Fri Apr 02, 2021 12:48 am
Been thanked: 59 times

Re: LoRaWAN - RAK WIRELESS

Post by tcpipchip »

wow...i didnt try the patch...i will do late! thanks
User avatar
Fernando Perez
Posts: 378
Joined: Mon Feb 15, 2021 10:09 pm
Location: Santander (Spain)
Has thanked: 195 times
Been thanked: 267 times

Re: LoRaWAN - RAK WIRELESS

Post by Fernando Perez »

tcpipchip, I apologize in advance.
I never give my opinion on my colleagues' way of programming, but when I see a GOTO, I'm screwed.
I suppose you come from an assembly environment and that makes things look different, but Basic has a different approach.
I don't have nor have I ever used a LORA device, so I can't check if my lines of code work, but they are just to explain better what I mean. Google Translate fails a lot, but with programming code we all understand each other better.
I haven't touched on the part that checks for "+EVT:RX_1" because I don't know what the full string you get looks like, but if you tell me, I can try. In any case, there must be a mistake in the last 's$= left$(s$,instr(s$, "+EVT") - 1) ', because I don't understand the -1 very well.
And I repeat, sorry for my interference.

Code: [Local Link Removed for Guests]

ERRORS_LINKCHECK = 0
JOINED$ = "NO"
FAIL$ = "NO"
fail = 0

pin.mode 2, output  : pin(2)  = 0 
pin.mode 5, output  : pin(5)  = 0
pin.mode 18, output : pin(18) = 0
pin.mode 19, output : pin(19) = 0
pin.mode 23, output : pin(23) = 0

serial2.mode 115200, 13, 15
onserial2 rec2

gosub boot

do
  printAT "AT+NJS=?"
  pause 19500
  if JOINED$ = "YES" then gosub joined
  if FAIL$ = "YES" then gosub boot
loop

END

' -------------------
boot:
  ERRORS_LINKCHECK = 0
  JOINED$ = "NO"
  FAIL$ = "NO"
  pin(2) = 0
  pause 20000 ' Pause enough to receive the JOIN
  if JOINED$ = "YES" then return

  printAT "AT+NWM=1"                                    ' enable LoRaWAN 
  printAT "AT+LINKCHECK=2"                              ' enable linkcheck message 
  printAT "AT+DEVEUI=0080e115051fd80a"                  ' DEV EUI 
  printAT "AT+APPKEY=a614d59963a0861edf2702ae6f0e1ad6"  ' APP KEY
  printAT "AT+BAND=6"                                   ' AU915 
  printAT "AT+MASK=0002"                                ' MASK (regional parameters)  
  printAT "AT+CLASS=A"                                  ' CLASS A 
  printAT "AT+CFM=0"                                    ' no confirmation downlink 
  printAT "AT+TXP=14"                                   ' TX POWER 14
  printAT "AT+ADR=1"                                    ' adaptative data rate  
  printAT "AT+PNM=1"                                    ' private network  
  printAT "AT+JOIN=1:0:10:8"                            ' auto join  
return

' -------------------
joined:
  pin(2) = 1
  FAIL$ = "NO"
  print "Sending Package"
  printAT "AT+MASK=0002"
  printAT "AT+SEND=2:AAAAAAAA"
return

' -------------------
rec2:
  r$ = serial2.input$
  print r$
  fail = 0

  if instr(r$, "AT_NO_NETWORK_JOINED") > 0 then fail = 1
  if instr(r$, "AT+NJS=0") > 0 then fail = 1
  if instr(r$, "+EVT:SEND_CONFIRMED_FAILED") > 0 then fail = 1
  if instr(r$, "+EVT:JOIN_FAILED_RX_TIMEOUT") > 0 then fail = 1
  if instr(r$, "+EVT:LINKCHECK:1:0:0:0:0") > 0 then incr ERRORS_LINKCHECK
  if ERRORS_LINKCHECK = 3 then fail = 1
  
  if fail = 1 then
    FAIL$ = "YES"  
    JOINED$="FALSE"
    ERRORS_LINKCHECK = 0
    return
  endif
  
  if instr(r$, "+EVT:LINKCHECK") > 0 then print "Package Sent"
    
  if instr(r$, "JOINED") > 0 then
    PRINT "CONGRATULATIONS, JOINED"
    JOINED$="YES"
    return
  endif

  if instr(r$, "+EVT:RX_1") > 0 then
    s$= mid$(r$, instr(r$, ":") + 1)
    s$= mid$(s$, instr(s$, ":") + 1)
    s$= mid$(s$, instr(s$, ":") + 1)
    s$= mid$(s$, instr(s$, ":") + 1)
    s$= mid$(s$, instr(s$, ":") + 1)
    s$= mid$(s$, instr(s$, ":") + 1)
    s$= left$(s$,instr(s$, "+EVT") - 1)

    if instr(s$, "31") > 0 then pin(23) = 1  
    if instr(s$, "32") > 0 then pin(19) = 1  
    if instr(s$, "33") > 0 then pin(18) = 1  
    if instr(s$, "34") > 0 then pin(5)  = 1  
    if instr(s$, "35") > 0 then pin(23) = 0  
    if instr(s$, "36") > 0 then pin(19) = 0  
    if instr(s$, "37") > 0 then pin(18) = 0  
    if instr(s$, "38") > 0 then pin(5)  = 0 

   endif
 
return

' -------------------
SUB printAT(message$)
  print2 message$ + chr$(13) + chr$(10)
  pause 500
END SUB

User avatar
cicciocb
Site Admin
Posts: 1997
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 428 times
Been thanked: 1336 times
Contact:

Re: LoRaWAN - RAK WIRELESS

Post by cicciocb »

As a general rule, I always invite to avoid the use of GOTO.
It is a bad habit and can cause unexplained problems in the code.

In particular, entering or exiting with a GOTO from/to inside a loop or a IF / ENDIF into another part of the code can product problems like this.

To simplify, the interpreter verify, all the time, that the conditional blocks are correctly closed.

Let's give an example with the IF THEN ELSE ENDIF

From a practical point of view, there is a counter that is incremented when entering into an IF and decremented when reaching an endif

For example in this loop

Code: [Local Link Removed for Guests]

if a = 0 then
  ......   'here the "counter" value is 1
  if b = 20 then
   .... 'here the "counter" value is 2
  end if  'here the "counter" value is 1
end if 'here the "counter" value is 0
So, in a normal code, this "counter" should always return to 0

Now in this example

Code: [Local Link Removed for Guests]

.....
z = 0
if z = 0 then
  goto jumphere  'here the "counter" value is 1 but then it jumps to "jumphere:"
endif
....
....
if a = 0 then
  ......   
  if b = 20 then
jumphere:
   ....    'here the "counter" value is 1
  end if   'here the "counter" value is 0
end if   'here the "counter" value is -1  -> this trigger the alert ENDIF WITHOUT IF
You can also have the reverse effect, i.e. that the counter increase all the time because the program never passes through the ENDIF.
In this case, because the IF positions are stored for performances purposes (there is a "stack" of 32), this can also trigger the same error message

I did a patch in the latest version just to limit the stack but I strongly suggest to avoid GOTO and use SELECT CASE and/or IF ELSEIF
tcpipchip
Posts: 76
Joined: Fri Apr 02, 2021 12:48 am
Been thanked: 59 times

Re: LoRaWAN - RAK WIRELESS

Post by tcpipchip »

thank you so much!

Yes, i came from Assembly from 8080, 6502, Z80, 8086...

Yes...when i used GOTO, i thought, why to use ? It´s not good...but...it was a solution that i found that time...but will change :)

And the better, make an issue
User avatar
cicciocb
Site Admin
Posts: 1997
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 428 times
Been thanked: 1336 times
Contact:

Re: LoRaWAN - RAK WIRELESS

Post by cicciocb »

[Local Link Removed for Guests] wrote: [Local Link Removed for Guests]Tue Nov 28, 2023 12:12 pm thank you so much!

Yes, i came from Assembly from 8080, 6502, Z80, 8086...

Yes...when i used GOTO, i thought, why to use ? It´s not good...but...it was a solution that i found that time...but will change :)

And the better, make an issue

Hi Miguel,
so the patch worked for you?
tcpipchip
Posts: 76
Joined: Fri Apr 02, 2021 12:48 am
Been thanked: 59 times

Re: LoRaWAN - RAK WIRELESS

Post by tcpipchip »

[Local Link Removed for Guests] wrote: [Local Link Removed for Guests]Fri Nov 24, 2023 1:08 pm tcpipchip, I apologize in advance.
I never give my opinion on my colleagues' way of programming, but when I see a GOTO, I'm screwed.
I suppose you come from an assembly environment and that makes things look different, but Basic has a different approach.
I don't have nor have I ever used a LORA device, so I can't check if my lines of code work, but they are just to explain better what I mean. Google Translate fails a lot, but with programming code we all understand each other better.
I haven't touched on the part that checks for "+EVT:RX_1" because I don't know what the full string you get looks like, but if you tell me, I can try. In any case, there must be a mistake in the last 's$= left$(s$,instr(s$, "+EVT") - 1) ', because I don't understand the -1 very well.
And I repeat, sorry for my interference.

Code: [Local Link Removed for Guests]

ERRORS_LINKCHECK = 0
JOINED$ = "NO"
FAIL$ = "NO"
fail = 0

pin.mode 2, output  : pin(2)  = 0 
pin.mode 5, output  : pin(5)  = 0
pin.mode 18, output : pin(18) = 0
pin.mode 19, output : pin(19) = 0
pin.mode 23, output : pin(23) = 0

serial2.mode 115200, 13, 15
onserial2 rec2

gosub boot

do
  printAT "AT+NJS=?"
  pause 19500
  if JOINED$ = "YES" then gosub joined
  if FAIL$ = "YES" then gosub boot
loop

END

' -------------------
boot:
  ERRORS_LINKCHECK = 0
  JOINED$ = "NO"
  FAIL$ = "NO"
  pin(2) = 0
  pause 20000 ' Pause enough to receive the JOIN
  if JOINED$ = "YES" then return

  printAT "AT+NWM=1"                                    ' enable LoRaWAN 
  printAT "AT+LINKCHECK=2"                              ' enable linkcheck message 
  printAT "AT+DEVEUI=0080e115051fd80a"                  ' DEV EUI 
  printAT "AT+APPKEY=a614d59963a0861edf2702ae6f0e1ad6"  ' APP KEY
  printAT "AT+BAND=6"                                   ' AU915 
  printAT "AT+MASK=0002"                                ' MASK (regional parameters)  
  printAT "AT+CLASS=A"                                  ' CLASS A 
  printAT "AT+CFM=0"                                    ' no confirmation downlink 
  printAT "AT+TXP=14"                                   ' TX POWER 14
  printAT "AT+ADR=1"                                    ' adaptative data rate  
  printAT "AT+PNM=1"                                    ' private network  
  printAT "AT+JOIN=1:0:10:8"                            ' auto join  
return

' -------------------
joined:
  pin(2) = 1
  FAIL$ = "NO"
  print "Sending Package"
  printAT "AT+MASK=0002"
  printAT "AT+SEND=2:AAAAAAAA"
return

' -------------------
rec2:
  r$ = serial2.input$
  print r$
  fail = 0

  if instr(r$, "AT_NO_NETWORK_JOINED") > 0 then fail = 1
  if instr(r$, "AT+NJS=0") > 0 then fail = 1
  if instr(r$, "+EVT:SEND_CONFIRMED_FAILED") > 0 then fail = 1
  if instr(r$, "+EVT:JOIN_FAILED_RX_TIMEOUT") > 0 then fail = 1
  if instr(r$, "+EVT:LINKCHECK:1:0:0:0:0") > 0 then incr ERRORS_LINKCHECK
  if ERRORS_LINKCHECK = 3 then fail = 1
  
  if fail = 1 then
    FAIL$ = "YES"  
    JOINED$="FALSE"
    ERRORS_LINKCHECK = 0
    return
  endif
  
  if instr(r$, "+EVT:LINKCHECK") > 0 then print "Package Sent"
    
  if instr(r$, "JOINED") > 0 then
    PRINT "CONGRATULATIONS, JOINED"
    JOINED$="YES"
    return
  endif

  if instr(r$, "+EVT:RX_1") > 0 then
    s$= mid$(r$, instr(r$, ":") + 1)
    s$= mid$(s$, instr(s$, ":") + 1)
    s$= mid$(s$, instr(s$, ":") + 1)
    s$= mid$(s$, instr(s$, ":") + 1)
    s$= mid$(s$, instr(s$, ":") + 1)
    s$= mid$(s$, instr(s$, ":") + 1)
    s$= left$(s$,instr(s$, "+EVT") - 1)

    if instr(s$, "31") > 0 then pin(23) = 1  
    if instr(s$, "32") > 0 then pin(19) = 1  
    if instr(s$, "33") > 0 then pin(18) = 1  
    if instr(s$, "34") > 0 then pin(5)  = 1  
    if instr(s$, "35") > 0 then pin(23) = 0  
    if instr(s$, "36") > 0 then pin(19) = 0  
    if instr(s$, "37") > 0 then pin(18) = 0  
    if instr(s$, "38") > 0 then pin(5)  = 0 

   endif
 
return

' -------------------
SUB printAT(message$)
  print2 message$ + chr$(13) + chr$(10)
  pause 500
END SUB

Fernando, works cool your code, thanks :)
image.png
You do not have the required permissions to view the files attached to this post.
User avatar
Fernando Perez
Posts: 378
Joined: Mon Feb 15, 2021 10:09 pm
Location: Santander (Spain)
Has thanked: 195 times
Been thanked: 267 times

Re: LoRaWAN - RAK WIRELESS

Post by Fernando Perez »

I'm very happy, tcpipchip.
As I was saying to you, I would like you to send me the complete string that you receive in the message "+EVT:RX_1", because I think that part could be greatly simplified.
Post Reply