BLE-LoRa - Smartphone communication with LoRa/BLE亨之寶


誠之Net Open Source 分享

介紹(Introduction)

(這個裝置原來的名字叫"亨之寶",因為它原先是由我的學長陳冠亨想到的點子,後續的開發是由我們接手,後來才給他取了新的名字"誠之net"。)

幾乎每人都有智慧型手機,每天都在用的Line等訊息服務,均完全依賴電信公司3G/4G與WiFi網路,也因此所有通訊服務都被電信公司所綁架。

我們開發“誠之Net”,讓所有使用者的智慧型手機不需要依賴電信公司網路,也可相互傳訊息,進而提供有趣的Location-Based Service (LBS)。

The original name of this device is "Hun Zi Bow". Because it was originally the idea that my senior brother in the lab, Chen Guanheng, thought of. Subsequent development is taken over by us and we gave it a new name "誠之net".

Almost everyone has a smartphone and use message service like Line everyday. All of these applications depends on 3G/4G or WiFi network .Therefore, all communication services are abducted by telecommunications companies.

We develop "Chen Zi Net" to let all users' smartphones can communicate with each other without relying on the telecommunications company network.


架構說明(Architecture Description)


上圖中“誠之Net”即為本架構核心裝置,其為低功率藍芽BLE與LoRa無線訊號轉換裝置,實際外型,可作成如"手機背蓋"、或者"行動電源"等會隨身攜帶的裝置。

智慧型手機透過BLE與"誠之Net"連線,其再透過LoRa等長距離的通訊技術把訊息傳輸到遠方他人的"誠之Net",因此可以不依賴電信商網路也可交換類似Line的訊息。

使用者隨身攜帶的"誠之Net"可透過我們自行開發的手機APP(類似Line的功能,傳圖與文字)來收送的訊息。因此我們就算於無電信公司服的區域(或者該手機根本無申請上網門號時),也可互相傳送uni-cast或者broadcast訊息給其他有"誠之Net"的使用者。搭配轉發與mesh架構可以把訊息傳到更遠的地方。

此外,此架構亦可以提供LBS功能。例如學校餐廳在地下室,外界人員無法直接看到是否現在有營業。本架構亦提供感測器端,可以搭配適當感測器(如上圖中的PIR)來偵測某商店是否有營業且有人員進出,進而透過LoRa來傳輸到上圖中“伺服器”,並顯示在餐廳門口/道路附近的顯示器告知大眾。

"誠之Net(Chen Zi Net)",in the above picture ,is the core device of this architecture. It is a low power BLE and LoRa wireless signal conversion device. And its real exterior can be used as a device such as "mobile phone back cover" or "mobile power supply".

Smart phone connect with Chen Zi Net via BLE and then transmit the message to the other "Chen Zi Net" through long-distance communication technology such as LoRa. Therefore,it is possible to exchange messages similar to Line without relying on the telecommunications company network.

The "Chen Zi Net" that users carry with them can send messages through the APP we developed (similar to Line function, send picture or text).Therefore, even if there is no telecommunications company service area (or the mobile phone does not apply for the Internet access number ), we can also send uni-cast or broadcast messages to other users who have "Chen Zi Net".

In addition, this architecture can also provide LBS functionality.For example, if the school restaurant is in the basement, outsiders cannot directly see it is open or not. This architecture also provides a sensor side that can be used with a suitable sensor (PIR in the figure above) to detect if a store is open and has personnel in and out.

And then transmitted to the "伺服器"(server) in the above figure through LoRa and displayed on the display near the restaurant door/road to inform the public.


開發進度-硬體端(Hardware)

Chen Zi Net made of NRF52832 module + BLE + LoRa

LoRa setting:Frequency = 433MHz,bandwidth=500000Hz,SF=7

透過藍芽中斷的方式從手機接收資料並用LoRa傳出,傳輸過程中的封包有經過XOR做簡單加密(目前是註解掉的)

由於BLE協定的關係,從手機接收到的資料一次最多只能收到20Bytes,後面的資料會被切掉,所以為了送更長的訊息出去,在APP方面用多封包的方式來傳送

Receive data from your phone via Bluetooth interrupt and send it out with LoRa. The packet in the transmission process is simply encrypted by XOR (currently commented)

Due to the BLE protocol,The data received from the phone can only receive up to 20 bytes at a time. The data more than 20 bytes will be cut off, so in order to send a longer message, we use the multi-packet method to transmit in the APP.

開發進度-軟體端(Software)

系統要求(System Requirement)

使用者可以透過我們開發的APP來與裝置連線,不過由於APP內BLE的API要求,需使用Android 6.0以上版本的裝置才能使用,且使用APP時需要打開定位並授權APP定位功能才能正常掃到裝置的BLE(不需要有訊號或網路也可以,只是定位功能跟授權要打開)

Smart phone system: At least Android 6.0

When users using APP, they MUST open the "location service" and authorize the APP use "location service". If not, they can't scan the device of "Chen Zi Net". (Users don't need Network or telecommunications signal ,just open the service and authorization)


多封包機制(Multi-packet mechanism)

為了能送出更長的訊息,APP端有能夠送多封包的機制,透過計算訊息的UTF-8的bytes數,來把資料分批寫進BLE的buffer,目前最多可以一次送5個封包(怕送太多容易掉封包)

In order to send longer message, app calculate the bytes of message in UTF-8 and then write the data into the BLE buffer in batches.

Up to 5 packets can be sent at a time.(I afraid to send too many easy to drop packets)

重送機制(Resend mechanism)

當接收端的裝置(ex:手機)收到時會回送ACK,若是傳送端沒有收到ACK會判斷為封包有遺失,會在送出訊息後延遲2秒,在開始重送訊息,重送封包的間隔為1秒,送10次失敗就停止重送。

Receiver will send ACK when it receive data. If transmitter doesn't receive ACK, it will determine that packet is lost.

Transmitter will delay 2 seconds after it send the message. And the start to resend message. The interval of resend message is 1 second. It will stop if it fail 10 times.

加密機制(Encrypt mechanism)

APP透過BLE送訊息給誠之Net時,一樣會有簡單的XOR加密機制,接收段收到資料會再解密。

When the APP sends a message to Chen Zi Net via BLE, there will be a simple XOR encryption mechanism, and the receiving segment will decrypt the data.

APP -> Chen Zi Net :XOR

Chen Zi Net ->Chen Zi Net : XOR

Total two XOR encryptions.


使用示範(Demonstrate)

YouTube 影片


應用(Application)

目前最簡單的應用有像LINE一樣傳送訊息的功能,不需要依賴電信或網路。

原本設計的應用如影片介紹的,用於偵測一些訊號較差的地方(如地下室)的商店有沒有營業,然後把資訊傳送到門口的大看板。

但是這個架構應該還可以應用在更多的地方,所以教授建議弄一個平台將這些成果open source,讓大家可以加入開發的行列

The simplest application has the ability to send messages like LINE without relying on telecommunications or the Internet.

The original design application, as described in the video, is used to detect whether the shops with poor signals (such as the basement) are open or not, and then send the information to the big screen at the door.

But this architecture should be able to be applied in more situations , so my professor suggested to make a platform to open the source of these results, so that more people can join the development.


誠之Net & APP 程式碼(Chen Zi Net & APP code)

封包格式(Packet Specification)

封包傳輸(Packet Transmition)

聯絡資訊(Contact Information)

My Email :wizoza22222@gmail.com

My professor Warren Lee: huclee.nthu@gmail.com

web analysis site