changed 5 years ago
Linked with GitHub

物聯網 Lab4

物聯網目錄:

顯示地圖於 google ver.2

達成目標

基本功能:

  • 傳送自己位置藉由 Node-RED 給 OM2M
  • Node-RED 訂閱並處理資料與存放 (寫檔)
  • 從 Node-RED 獲取目前資料 (讀檔)
  • 顯示 google 地圖

額外功能:

  • 傳送位置時改用 notifier 顯示狀況
  • 延續 Lab2,直接用兩個 web 模擬兩支手機

版面設計

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

大體類似 Lab2,一樣先幫這幾個元件填入初始值

  • web_sendUrl 填入 http://電腦的 IPv4:1880/GPS
  • web_getUrl 填入 http://電腦的 IPv4:1880/INFO
  • ActivityStarter1Activity 填入 android.intent.action.VIEW

程式設計

App inventer 變動不大,Get 一樣是以 , 來分割收到的資訊,同時把變數的使用降低

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Node-RED 部分先拉出以下所示

  • Data_sub:設定 DATA 如果有新物件,會通知 /SUB
  • /GPS:接收 App 傳來的位置資訊,加到 DATA
  • /SUB:被通知時進行字串處理,最終將 obj 部分擷取出來寫檔 (相對路徑為使用者目錄下)
  • /INFO:App Get 時,讀檔並字串處理,回傳以 , 分隔的位置資訊

/SUB 字串處理的部分可以參考物聯網環境建置與測試最後面

多善用 debug 來看路徑

/INFO 字串處理只需要擷取經緯度如下,App 即可用 , 分割

var lat = msg.payload.obj.str[0].$.val; var lon = msg.payload.obj.str[1].$.val; msg.payload = lat + "," + lon; return msg;

實際畫面

先模擬定位至安平古堡

傳送給 Server

從 Server 獲取

Select a repo