PricelessToolkit / MailBoxGuard

Lora Long Range Mailbox Sensor for Smart Homes or for Standalone use
BSD 3-Clause "New" or "Revised" License
182 stars 28 forks source link

Request: OTAA #6

Closed WhistleMaster closed 4 months ago

WhistleMaster commented 1 year ago

Hi !

Thanks again the great work on those projects!

I was wondering if that would be possible to have a version of the sensor code which would use OTAA to join other Lora networks such as TTN ?

Thanks ! Kind regards,

WM

PricelessToolkit commented 1 year ago

Hi!

I think there is only one gateway in my area and it is far away, so I have never tried using TTN. But if I find free time, I'll try. Do you have experience with Arduino coding?

WhistleMaster commented 1 year ago

Thanks ! I have a bit of experience with Arduino coding. I've found some example such as MailboxNotifier, similar to the MaiBoxGuard sensor, but using OTAA to join LoraWan networks or also LilyGo.

WhistleMaster commented 1 year ago

Based on those examples, I've tried something: ttn_otaa.ino.zip but the issue I have is, I guess, the limited size of the micro controller Attiny1616 because I get an error at compilation which is:

region `text' overflowed by 9345 bytes
PricelessToolkit commented 1 year ago

can you attach libraries too?

WhistleMaster commented 1 year ago

Sure ! The only additional one needed is MCCI_LoRaWAN_LMIC_library libraries.zip

PricelessToolkit commented 1 year ago

Error compiling for board ATtiny3226/3216/1626/1616/1606/826/816/806/426/416/406. Library not working with Attiny1616

WhistleMaster commented 1 year ago

This is where my competences with Arduino coding stop I guess. I'll leave you mastering it better than I could do 😄

PricelessToolkit commented 1 year ago

I'm more into hardware than software so nop! 😊

WhistleMaster commented 1 year ago

I've found another lib from Adafruit which could be good for OTAA. I'd need the following PINs.

I had a look at the schematic but I'm not sure which pin of the Ai-Thinker-Ra you used.

Thanks !

PricelessToolkit commented 1 year ago

ARDUINO | ATTINY | LORA

GPIO14 - PA1 - MOSI GPIO15 - PA2 - MISO GPIO16 - PA3 - SCK/CLK GPIO1 - PA5 - RESET GPIO10 - PC0 - NSS

WhistleMaster commented 1 year ago

Thanks !

I have the NSS and the RST pins, but I still don't get what the interrupt pin is. Should be DI0 on the LoRa chip but to what pin on the ATTINY is it connected ?

lora
PricelessToolkit commented 1 year ago

DI0 is not connected, Since the sensor does not have a sleep mode "power is completely turned off" DI0 is not used. DI0 is used for two-way comunication "if I understand correctly". So DI0 is not required.

PricelessToolkit commented 1 year ago

"The dio0 pin can be used for channel activity detection callback, transmission finish callback and/or receiving callback, check onCadDone , onTxDone, and onReceive."

WhistleMaster commented 1 year ago

So what would be the module's interrupt pin ?

PricelessToolkit commented 1 year ago

LoRa module doesn't have an interrupt pin, its microcontroller has one, "DI0 ->Interupt capable MCU pin" but it's not connected.

WhistleMaster commented 1 year ago

Is this closed because the sensor has now the OTAA function ?

PricelessToolkit commented 1 year ago

I closed it because of inactivity + the interrupt pin is not connected to the LoRa module.

WhistleMaster commented 1 year ago

Well, we can keep it open, just in case someone is interested to jump in to help :)

PricelessToolkit commented 1 year ago

ok

WhistleMaster commented 1 year ago

I've done other tests and unfortunately the TinyLora lib from Adafruit is not compatible with TTNv3... and it seems that there is no other lib working with the Attiny1616...

PricelessToolkit commented 1 year ago

Hi, if i understand correctly TTN uses one-way communication, then why all TTN libs require DI0 I can't understand.

WhistleMaster commented 1 year ago

It seems to be related to single-channel packet forwarders that no longer work after the Things Network migration to The Things Stack v3. according to that forum thread: https://www.thethingsnetwork.org/forum/t/single-channel-packet-forwarders-scpf-are-deprecated-and-not-supported/31117

WhistleMaster commented 11 months ago

I found the following project https://github.com/novag/LoRa-ATtiny-Node, for ATtiny85, which implements the ABP and OTAA.

Maybe that could also work with the Attiny1616 ?

PricelessToolkit commented 10 months ago

Autor says "Currently this library is heavily optimized for ATtiny85 chips and needs changes to run on other devices" + "It has support for downlink messages" it uses "DI0" too, so I don't think it will work.

WhistleMaster commented 10 months ago

That's a pity... I found somewhere that you could also achieve the OTAA by sending AT commands, such as the following:

AT+CJOINMODE=0
AT+CRXP=1,1,869525000
AT+CDEVEUI=70B3D57ED0052256
AT+CAPPEUI=0000000000000000
AT+CAPPKEY=8D5EC8F6834BDE677A3D815E81A14981
AT+CFREQBANDMASK=0001
AT+CULDLMODE=2
AT+CJOIN=1,1,8,8
AT+DTRX=0,2,6,445566
AT+DTRX=1,1,4,5555

Is that something that could be supported by the lora chip you use ?

EDIT: I found this example.

PricelessToolkit commented 10 months ago

Hi, unfortunately, no! These AT commands for assemblies like the "MCU+LoRa" stand-alone LoRa chip can't support AT commands, "it does not speak TTL"

itopaloglu83 commented 9 months ago

I was about to ask about the same The Things Network (TTN) support when I found this issue. It is quite unfortunate that we are not able to make it work. Thank you for all the research and experimentation.

Could you provide a summary of what the problem is? I'm not very familiar with the requirements for TTN so I would like to research it a little bit more. The form link about talks about packet forwarders but my understanding is that MailBoxGuard would be an end node only.

PricelessToolkit commented 9 months ago

The problem is that this sensor was not designed to work with TTN, "I didn't know that to work with TTN" I needed to connect the DI0 LoRa pin to an interrupt-capable MCU pin. "it is for detecting when the transmission is done" TTN libraries require this connection, but I don't know why....

itopaloglu83 commented 9 months ago

First of all, you did a great job with the board and the video. I already bought one and now experimenting to see if I can get away with not having a gateway and use TTN instead. It's a fun side project to tinker with.

Arduino LoRa library says that the DIO0 is optional and it is only needed for the receive callback mode. I also remember watching Andreas Spiess' video about the MailboxNotifier, he used the interrupt to keep the MCU sleeping while the packets were being sent.

I'm going to read the sample codes above and see if there's any walk around.

itopaloglu83 commented 9 months ago

This update is for any future curious souls. After experimenting with an OTAA capable board for a while and realizing that there is no TTN gateway close to where I live, I abandoned figuring out how to connect MailboxGuard to TTN.

PricelessToolkit commented 9 months ago

This update is for any future curious souls. After experimenting with an OTAA capable board for a while and realizing that there is no TTN gateway close to where I live, I abandoned figuring out how to connect MailboxGuard to TTN.

Thanks for trying, I don't have a close gateway either.

WhistleMaster commented 9 months ago

I do have a gateway and would be really happy to test !

itopaloglu83 commented 9 months ago

I don't have an exact procedure to follow but here's the approach I was planning to take.

Practically speaking, the interrupt functionality is only needed when the LoRa Radio module is receiving a package and needs to inform the microcontroller about it. This is required because during OTAA setup, various back-and-forward communication takes place to exchange encryption keys etc. One could theoretically make a small sketch that registers to the TTN network by sending the required messages (APPID etc.) and then polling for a response from the radio instead of using the interrupts. In a way, writing an alternative LoRaWan library that can work on AtTiny1616.

If you just want to experiment without writing your own LoRaWan library, you can try something like Dragino LDS02 that is already capable of joining TTN via OTAA.

WhistleMaster commented 8 months ago

Yes, indeed, we could use another sensor from Dragino but it would be better to use the MailBoxGuard 🙂

PricelessToolkit commented 4 months ago

All will be fixed with the next HW version.