Note: IRI on Ubuntu 14.04.x

IRI 使用 Java 8, 的環境, 我測試Open JDK 8, 不過據某些網路上資訊是建議採用Orcale JDK 8
IRI 使用Maven 這個Build tool, 目前透過sudo apt-get install maven 可以直上 maven 3.0.5
按照Github 上面的指示可以做完後執行下面 shell script

#!/usr/bin/env bash
ver=1.4.2.1
port=14265
echo -e "run IOTA IRI version:${ver}, port:${port}"
java -jar target/iri-${ver}.jar -p $port

然後等它整各Service 跑起來, 會出現下面log, 在開另外一個terminal 透過curl 驗證是否正常

run IOTA IRI version:1.4.2.1, port:14265
02/23 12:19:04.742 [main] INFO  com.iota.iri.IRI - Welcome to IRI 1.4.2.1
02/23 12:19:20.124 [main] INFO  c.i.i.s.r.RocksDBPersistenceProvider - Initializing Database Backend... 
02/23 12:19:20.534 [main] INFO  c.i.i.s.r.RocksDBPersistenceProvider - RocksDB persistence provider initialized.
02/23 12:19:20.548 [main] INFO  com.iota.iri.network.UDPReceiver - UDP replicator is accepting connections on udp port 14600
02/23 12:19:20.550 [main] INFO  c.i.i.network.replicator.Replicator - Started ReplicatorSourcePool
02/23 12:19:20.550 [UDP receiving thread] INFO  com.iota.iri.network.UDPReceiver - Spawning Receiver Thread
02/23 12:19:20.551 [UDP receiving thread] INFO  com.iota.iri.network.UDPReceiver - Receiver thread processed/dropped ratio: 0/0
02/23 12:19:20.554 [Thread-2] INFO  c.i.i.n.r.ReplicatorSourcePool - TCP replicator is accepting connections on tcp port 15600
02/23 12:19:20.559 [pool-2-thread-1] INFO  com.iota.iri.network.Node - Spawning Broadcaster Thread
02/23 12:19:20.559 [pool-2-thread-2] INFO  com.iota.iri.network.Node - Spawning Tips Requester Thread
02/23 12:19:20.560 [pool-2-thread-3] INFO  com.iota.iri.network.Node - Spawning Neighbor DNS Refresher Thread
02/23 12:19:20.560 [pool-2-thread-3] INFO  com.iota.iri.network.Node - Checking Neighbors' Ip...
02/23 12:19:20.561 [pool-2-thread-4] INFO  com.iota.iri.network.Node - Spawning Process Received Data Thread
02/23 12:19:20.561 [pool-2-thread-5] INFO  com.iota.iri.network.Node - Spawning Reply To Request Thread
02/23 12:19:20.562 [pool-2-thread-2] INFO  com.iota.iri.network.Node - toProcess = 0 , toBroadcast = 0 , toRequest = 0 , toReply = 0 / totalTransactions = 0
02/23 12:19:30.563 [pool-2-thread-2] INFO  com.iota.iri.network.Node - toProcess = 0 , toBroadcast = 0 , toRequest = 0 , toReply = 0 / totalTransactions = 0
02/23 12:19:40.635 [main] INFO  com.iota.iri.IRI - IOTA Node initialised correctly.
02/23 12:19:45.563 [pool-2-thread-2] INFO  com.iota.iri.network.Node - toProcess = 0 , toBroadcast = 0 , toRequest = 0 , toReply = 0 / totalTransactions = 0

測試命令可以參考API 文件(v1.2.0), 底下我的測試命令用了 jq

curl -X POST -H "Content-Type: application/json" -H "X-IOTA-API-Version: 1" -d '{"command": "getNodeInfo"}' http://localhost:14265 | jq '.'

執行結果如下

{
  "duration": 0,
  "latestMilestone": "999999999999999999999999999999999999999999999999999999999999999999999999999999999",
  "jreTotalMemory": 1808269312,
  "jreMaxMemory": 3689414656,
  "jreVersion": "1.8.0_161",
  "jreFreeMemory": 817012944,
  "jreAvailableProcessors": 4,
  "appVersion": "1.4.2.1",
  "appName": "IRI",
  "latestMilestoneIndex": 338000,
  "latestSolidSubtangleMilestone": "999999999999999999999999999999999999999999999999999999999999999999999999999999999",
  "latestSolidSubtangleMilestoneIndex": 338000,
  "neighbors": 0,
  "packetsQueueSize": 0,
  "time": 1519361004170,
  "tips": 0,
  "transactionsToRequest": 0
}

ref.An almost complete guide to setting up a full IOTA node

廣告

亂想

今天看了一下IOTA 的一些東西, 看來IOTA 越來越確認目前不是那種萬物可上的狀態, 基本上它考慮了很多東西, 看起來MCU 是可以跑得起來因為只需要驗證交易而已, 但是忽略對外頻寬的壓力, 當然這個在未來10年內可能可以解除? 透過5G時代來臨的話也許對外頻寬成本可以解決? 不過估計短期(5年)內不可能已經是確定的, 目前最好的模式還是 還是在私有網路搭配一個 IoT Gateway的設計比較實際

IOTA 目前有Open Source 一個Full Node 實作 IRI (IOTA Reference Implementation)用的是 JAVA 8 and later(程式碼有用 lambda ), 從源碼看來是直接用undertow 去嵌入一個web server, 然後API.java 裡面的process() 函式處理那些API(commad)

目前因為很多東西還沒確定, 所以還持續演化中, 像是經過snapshot 後清掉所有交易紀錄只剩下當下Address 與 IOTA 的對應關係, 這有優點也有缺點, 優點是可以reduce database, 缺點是無法追蹤交易細節, 不過針對缺點有提了一個Permanodes 的提案, 但是啥時會有還不確定,個人估計今年應該就有才是

2018應該是AI & Blockchain 的爆發年,  然後2年後會死掉一堆公司, 這有點像2000年的.com 浪潮, 不過從歷史看, 新產業都是這樣, 大家一窩蜂投錢賭天使投資成功換回千倍回報, 不過天使投資100家能成2~3家就是很高的勝率!

IOTA 目前優勢是已經獲得國際上許多合作 看起來有蠻大的機會成功, 估計越多公司加入會驅使整個方案的成熟

不過重點還是資料來源是否是可靠的! 目前看來已經有許多硬體跟軟體正在整合中, 差不多這5年內, Trusted OS/Device 之類的會變成必須! 不過傳統裝置會不會有估計還是會佔多數, 不過會越來越偏就是了! 因為會變成基礎設施! 目前最大的問題還是看不出有統一的protocol, 不過可以看到各家(AWS IoT/Mbed Cloud) 都有在推自己的安全連線設計的embedded OS 環境, 方便終端裝置直接連上它們的管理界面, 做資料收集, 估計Amazon 的FreeRTOS之後一樣會有Hypervisor 才是

 

Note: Setup Python3.6 with VirtualEnv on Ubuntu 14.04 for CS231N

1. ref. Installing Python 3 on Linux to install python3.6

$ sudo apt-get install software-properties-common
$ sudo add-apt-repository ppa:deadsnakes/ppa
$ sudo apt-get update
$ sudo apt-get install python3.6 python3.6-dev

2. install pip & virtualenv

sudo apt-get install python3-pip
pip3 install virtualenv

3. ref. http://cs231n.github.io/assignments2017 for Working locally

cd assignment1
virtualenv -p /usr/bin/python3.6 . # Create a virtual environment (python3.6)
source bin/activate # Activate the virtual environment
pip install -r requirements.txt # Install dependencies
# Work on the assignment for a while …
deactivate # Exit the virtual environment

Tips: when meet “No matching distribution found for site==0.0.1 (from -r requirements.txt (line 42))" issues, just remove the line from file. the solve from this

Note: Dump HID Descriptor of Logitech Unifying receiver

dump HID descriptors
Bus 001 Device 003: ID 046d:c52b Logitech, Inc. Unifying Receiver


#!/bin/bash
echo -e "---------------interface 1---------------"
sudo cat /sys/kernel/debug/hid/0003:046D:C52B.0001/rdesc | head -n1 | xxd -r -p | hidrd-convert -o spec
echo -e "---------------interface 2---------------"
sudo cat /sys/kernel/debug/hid/0003:046D:C52B.0002/rdesc | head -n1 | xxd -r -p | hidrd-convert -o spec
echo -e "---------------interface 3---------------"
sudo cat /sys/kernel/debug/hid/0003:046D:C52B.0003/rdesc | head -n1 | xxd -r -p | hidrd-convert -o spec

Result


---------------interface 1---------------
Usage Page (Desktop),               ; Generic desktop controls (01h)
Usage (Keyboard),                   ; Keyboard (06h, application collection)
Collection (Application),
    Report Count (8),
    Report Size (1),
    Logical Minimum (0),
    Logical Maximum (1),
    Usage Page (Keyboard),          ; Keyboard/keypad (07h)
    Usage Minimum (KB Leftcontrol), ; Keyboard left control (E0h, dynamic value)
    Usage Maximum (KB Right GUI),   ; Keyboard right GUI (E7h, dynamic value)
    Input (Variable),
    Input (Constant, Variable),
    Report Count (5),
    Usage Page (LED),               ; LEDs (08h)
    Usage Minimum (01h),
    Usage Maximum (05h),
    Output (Variable),
    Report Count (1),
    Report Size (3),
    Output (Constant),
    Report Count (6),
    Report Size (8),
    Logical Minimum (0),
    Logical Maximum (255),
    Usage Page (Keyboard),          ; Keyboard/keypad (07h)
    Usage Minimum (None),           ; No event (00h, selector)
    Usage Maximum (FFh),
    Input,
End Collection
---------------interface 2---------------
Usage Page (Desktop),                   ; Generic desktop controls (01h)
Usage (Mouse),                          ; Mouse (02h, application collection)
Collection (Application),
    Report ID (2),
    Usage (Pointer),                    ; Pointer (01h, physical collection)
    Collection (Physical),
        Report Count (16),
        Report Size (1),
        Logical Minimum (0),
        Logical Maximum (1),
        Usage Page (Button),            ; Button (09h)
        Usage Minimum (01h),
        Usage Maximum (10h),
        Input (Variable),
        Report Count (2),
        Report Size (12),
        Logical Minimum (-2047),
        Logical Maximum (2047),
        Usage Page (Desktop),           ; Generic desktop controls (01h)
        Usage (X),                      ; X (30h, dynamic value)
        Usage (Y),                      ; Y (31h, dynamic value)
        Input (Variable, Relative),
        Report Count (1),
        Report Size (8),
        Logical Minimum (-127),
        Logical Maximum (127),
        Usage (Wheel),                  ; Wheel (38h, dynamic value)
        Input (Variable, Relative),
        Report Count (1),
        Usage Page (Consumer),          ; Consumer (0Ch)
        Usage (AC Pan),                 ; AC pan (0238h, linear control)
        Input (Variable, Relative),
    End Collection,
End Collection,
Usage Page (Consumer),                  ; Consumer (0Ch)
Usage (Consumer Control),               ; Consumer control (01h, application collection)
Collection (Application),
    Report ID (3),
    Report Count (2),
    Report Size (16),
    Logical Minimum (1),
    Logical Maximum (767),
    Usage Minimum (Consumer Control),   ; Consumer control (01h, application collection)
    Usage Maximum (02FFh),
    Input,
End Collection,
Usage Page (Desktop),                   ; Generic desktop controls (01h)
Usage (Sys Control),                    ; System control (80h, application collection)
Collection (Application),
    Report ID (4),
    Report Count (1),
    Report Size (2),
    Logical Minimum (1),
    Logical Maximum (3),
    Usage (Sys Sleep),                  ; System sleep (82h, one-shot control)
    Usage (Sys Power Down),             ; System power down (81h, one-shot control)
    Usage (Sys Wake Up),                ; System wake up (83h, one-shot control)
    Input,
    Report Size (6),
    Input (Constant, Variable),
End Collection,
Usage Page (FFBCh),                     ; FFBCh, vendor-defined
Usage (88h),
Collection (Application),
    Report ID (8),
    Report Count (1),
    Report Size (8),
    Logical Minimum (1),
    Logical Maximum (255),
    Usage Minimum (01h),
    Usage Maximum (FFh),
    Input,
End Collection
---------------interface 3---------------
Usage Page (FF00h),         ; FF00h, vendor-defined
Usage (01h),
Collection (Application),
    Report ID (16),
    Report Count (6),
    Report Size (8),
    Logical Minimum (0),
    Logical Maximum (255),
    Usage (01h),
    Input,
    Usage (01h),
    Output,
End Collection,
Usage Page (FF00h),         ; FF00h, vendor-defined
Usage (02h),
Collection (Application),
    Report ID (17),
    Report Count (19),
    Report Size (8),
    Logical Minimum (0),
    Logical Maximum (255),
    Usage (02h),
    Input,
    Usage (02h),
    Output,
End Collection,
Usage Page (FF00h),         ; FF00h, vendor-defined
Usage (04h),
Collection (Application),
    Report ID (32),
    Report Count (14),
    Report Size (8),
    Logical Minimum (0),
    Logical Maximum (255),
    Usage (41h),
    Input,
    Usage (41h),
    Output,
    Report ID (33),
    Report Count (31),
    Usage (42h),
    Input,
    Usage (42h),
    Output,
End Collection

Tool from https://github.com/DIGImend/hidrd

Note: How to use STM32F07x USB Device library

目前測試跟FreeRTOS v10.0.1 一起,
開啟HAL support 在 stm32f0xx_hal_conf.h 把下面這行 uncomment, 去enabled  USB low level driver
#define HAL_PCD_MODULE_ENABLED

接下來需要加上USB IRQ handler, 按照STM的範例 加在 stm32f0xx_it.c 裡面,
/* Private variables ———————————————————*/
extern PCD_HandleTypeDef hpcd;

void USB_IRQHandler(void)
{
HAL_PCD_IRQHandler(&hpcd);
}
在 main.c 裡面加上 下面三行, 這裡測試HID class device,
/* Init USB Device Library */
USBD_Init(&USBD_Device, &HID_Desc, 0);
/* Register the USB HID class */
USBD_RegisterClass(&USBD_Device, &USBD_HID);
/* Start Device Process */
USBD_Start(&USBD_Device);

然後複製一份 usbd_desc.h/usbd_conf.h 改成你要的
還有引入STM32F0xx USB Library 的USB Core/Class code 這樣就可以

Tips, 實際上還要注意USB Device 用的RAM (endpoint buffer)空間, 要避免RTOS override 不過還沒看這邊只是簡單測試
Update: STM32F0xx 的USB Endpoint buffer 是獨立於系統之外例如 測試的STM32F072RB 是指向 (0x40006000) 在 CMSIS 下的 stm32f072xb.h 內可以找到 #define USB_PMAADDR (APBPERIPH_BASE + 0x00006000)

Note: Parsing Payload of NDEF

NDEF Payload from Apple Watch 3

3C, 00, # Payload length??
----------------------------------------------------
02, 1C, # LE Role
01,     # Only Central Role supported
----------------------------------------------------
11, 23, # LE Secure Connections Random Value
EA, 4F, 59, 84, 1D, 0D, 90, 63, 97, C3, 82, BF, DC, 59, 15, B1,
---------------------------------------------------------------
11, 22, # LE Secure Connections Confirmation Value
44, FB, 74, 4A, 06, C7, E5, EE, 4B, 9A, B6, C2, E0, 4B, 87, 7D,
---------------------------------------------------------------
09, 09  # Complete Local Name (Session ID)
AA, BB, 3B, DE, 8B, XX, YY, ZZ
---------------------------------------------------------------
08, 1B, # LE Bluetooth Device Address
E4, B5, 0F, XX, XX, XX, 01
>>BLE ADDR: XX:XX:XX:0F:B5:E4, Resolvable private address, Core Spec. Vol 6, Part B, Section 1.3.2. 2

ref. https://www.nxp.com/products/identification-and-security/nfc/nfc-reader-ics/high-performance-nfc-controller-ic-with-support-for-apple-enhanced-contactless-polling-ecp:PN7150X