2018年1月16日 星期二

pysnmp startup

DOWNLOAD...
https://github.com/xfguo/pysnmp
http://snmplabs.com/pysnmp/
https://pypi.python.org/pypi/pysnmp/#downloads

INSTALL...
tar zxf package-X.X.X.tar.gz
cd package-X.X.X
python setup.py install
or...
pip install pysnmp
or...
easy_install pysnmp

EXAMPLE...
read…
http://www.nealc.com/blog/blog/2013/02/23/writing-an-snmp-agent-with-a-custom-mib-using-pysnmp/
readwrite…
http://www.cloud-rocket.com/2013/08/writing-custom-mib-for-pysnmp-agent/

1.create mib file MY-MIB
2.convert mib to py...
        build-pysnmp-mib -o MY-MIB.py MY-MIB
3.modify ip, get, trap functions
4.stop net-snmp
        service snmpd stop
        sudo update-rc.d snmpd disable
5.run example

        modify...
                ntfOrg = ntforg.NotificationOriginator(self._snmpContext)
        to...
                ntfOrg = ntforg.NotificationOriginator()
                ntfOrg.snmpContext = self._snmpContext

FIREWALL...
sudo iptables -A INPUT -p udp --dport 161 -j ACCEPT
or...
sudo ufw allow 161/udp

MIB BROWSER...
http://www.ireasoning.com/downloadmibbrowserfree.php

2017年12月21日 星期四

Modbus TCP Slaver using Python modbus-tk lib


https://github.com/ljean/modbus-tk/

install pip…
sudo apt-get install python-pip

install...
download modbus_tk-x.x.x.tar.gz
tar zxvf modbus_tk-x.x.x.tar.gz
python setup.py install

make sure your port is open...
sudo iptables -A INPUT -p tcp --dport 502 -j ACCEPT # for slaver
sudo iptables -A OUTPUT -p tcp --dport 502 -j ACCEPT  # for master

run example as root
a simple example...
import sys
import logging
import threading
import modbus_tk
import modbus_tk.defines as cst
import modbus_tk.modbus as modbus
import modbus_tk.modbus_tcp as modbus_tcp
import time

logger = modbus_tk.utils.create_logger(name="console", record_format="%(message)s")
# CREATE server
server = modbus_tcp.TcpServer() #DEFAULT PORT=502
slaver = server.add_slave(1) #ID=1

def setup():
    slaver.add_block("coil", cst.COILS, 0, 16)
    slaver.set_values("coil", 0, 16*[0])
       
def loop():
    logger.info("running...")
    # START
    server.start()
    while True:
        values = slaver.get_values("coil", 0, 8)
        #print values[0]
        str = ''
        for i in range(0, 8):
            if values[i] == 1:
                str = str + '1'
            else:
                str = str + '0'
        print  str
        # DELAY
        time.sleep(1)
        
def destory():
    logger.info("destory")
    # STOP
    server.stop()
       
if __name__ == "__main__":
    setup()
    try:
        loop()
    except KeyboardInterrupt:
        destory()


RaspberryPi BLE bluepy



install…
sudo apt-get install bluez
sudo hciconfig hci0 up

scan…
sudo hcitool lescan

or scan if no response...
sudo bluetoothctl
agent on
default-agent
scan on

other test...
using bluetoothctl

install bluepy…
https://github.com/IanHarvey/bluepy
sudo apt-get install python-pip libglib2.0-dev
sudo pip install bluepy

python test code…
from bluepy import btle
from bluepy.btle import Scanner, DefaultDelegate
import time
# Scan Delegate... 
class ScanDelegate(DefaultDelegate):
    def __init__(self):
        DefaultDelegate.__init__(self)

    def handleDiscovery(self, dev, isNewDev, isNewData):
        if isNewDev:
            print "Discovered device", dev.addr
        elif isNewData:
            print "Received new data from", dev.addr

print 'Scanning...'
scanner = Scanner().withDelegate(ScanDelegate())
devices = scanner.scan(3.0)

address = None
for dev in devices:
    print "Device %s (%s), RSSI=%d dB" % (dev.addr, dev.addrType, dev.rssi)
    for (adtype, desc, value) in dev.getScanData():
        print "  %s = %s" % (desc, value)
        if desc == 'Complete Local Name' and value == 'YOUR_BLE_DEVICE_NAME':
            address = dev.addr

print "Connecting..."

#address = "YOUR_FIX_DEVICE_MAC"
dev = btle.Peripheral( address )

print "Services..."
for svc in dev.services:
    print str(svc)
    chs = svc.getCharacteristics()
    for ch in chs:
        print '  ' + str(ch)
# Notification Delegate
class MyDelegate(btle.DefaultDelegate):
    def __init__(self):
        btle.DefaultDelegate.__init__(self)
        # ... initialise here

    def handleNotification(self, cHandle, data):
        print 'handleNotification:' + str(data)
        # ... perhaps check cHandle
        # ... process 'data'


# Initialisation  -------

dev.setDelegate( MyDelegate() )

service_uuid = btle.UUID("49535343-fe7d-4ae5-8fa9-9fafd205e455") # YOUR SERVICE UUID
char_uuid = btle.UUID("49535343-1e4d-4bd9-ba61-23c647249616") # YOUR CHARACTERISTICS UUID

# Setup to turn notifications on, e.g.
svc = dev.getServiceByUUID( service_uuid )
ch = svc.getCharacteristics( char_uuid )[0]
# Here is how to write a value to Notification Characteristic... 
write_handle = ch.getHandle()
notify_handle = ch.getHandle() + 1
dev.writeCharacteristic( notify_handle, bytes("\x01"), withResponse=True)

time.sleep(1.0)

# Main loop --------
while True:
    if dev.waitForNotifications(1.0):
        # handleNotification() was called
        continue

    print "Waiting..."
    # Perhaps do something else here
    # Here is how to write a value to Characteristic
    dev.writeCharacteristic( write_handle, bytes("A"), False ) # YOUR DATA

2017年8月24日 星期四

Building BetaFlight

Building BetaFlight

@UBUNTU/WIN10-BASH


Toolchain
sudo add-apt-repository ppa:team-gcc-arm-embedded/ppa
sudo apt-get update
sudo apt-get install gcc-arm-embedded
sudo apt-get install build-essential   /// for gcc if needed

SSH Key
ssh-keygen -t rsa -b 4096 -C "youraccount@git.hub"
cat ~/.ssh/id_rsa.pub
ssh-add ~/.ssh/id_rsa

GitHub new ssh key

Make
sudo apt-get install git   /// if needed
git clone git@github.com:betaflight/betaflight.git
cd betaflight
sudo make TARGET=NAZE


Update
git reset --hard
git pull
sudo make clean TARGET=NAZE


2017年7月17日 星期一

iOS App 上架駁回


由於是藍牙產品,App 需要連線才能動作,所以審核員也會要求你將硬體寄送過去給 Apple

底下是遭駁回的理由…

Guideline 2.1 - Information Needed

Thank you for your resubmission. We have started the review of your app, but we are not able to continue because we need the associated hardware to fully assess your app features.

Next Steps

To help us proceed with the review of your app, please send the necessary hardware/accessory to the address below.

NOTE: Please include your app name and app ID in the shipment; failure to provide this information can delay the review process.

Additionally, it may take several business days for us to receive the hardware once it has been delivered to Apple.

Apple, Inc.
1 Infinite Loop, M/S: 124-2APP
Cupertino, CA 95014
USA


解決方法…

先嘗式拍攝一段完整的DEMO影片回覆看看。
(後續:已審核通過)



2017年7月13日 星期四

iOS App 發佈出現錯誤-ERROR ITMS-90086


iOS App 發佈出現底下錯誤…
ERROR ITMS-90086: "Missing 64-bit support. iOS apps submitted to the App Store must include 64-bit support and be built with the iOS 8 SDK or later. We recommend using the default "Standard Architectures" build setting for "Architectures" in Xcode, to build a single binary with both 32-bit and 64-bit support." 

試了很久才總算 OK(上架真麻煩),但仍不知真正原因所在,記錄一下過程,應該多少有幫助…

有使用 CocoaPods 的話檢查一下專案(包含自己的及Pods的) signing 及 target 設定是否有錯,並記得 pod update 一下
檢查一下 Architectures 是否有錯,建議使用 Standard architectures
檢查一下 Valid Architectures 是否有錯,需包含 arm64
試試看 Bulid Settings 中 Enable bitcode 設為 No 是否有效


另外 iOS 10 以後,存取使用者私密資料 privacy-sensitive data 都要加上 usage description string,使用藍牙之類的週邊裝置也要加上相應的,不能留空白。

2017年6月5日 星期一

nRF51 Development Kit 開發環境

nRF51 Development Kit

開發環境安裝…

安裝 Keil 5

Keil - Pack Installer / Update

安裝 Device Family Pack
https://developer.nordicsemi.com/nRF5_SDK/
e.g. NordicSemiconductor.nRF_DeviceFamilyPack.8.11.1.pack

安裝 CMSIS pack
https://github.com/ARM-software/CMSIS/releases
e.g. ARM.CMSIS.4.5.0.pack

Keil 選單 project/manage/select software packs


VirtualBox 空間減肥

sdelete64 -z c: VBoxManage  modifymedium  disk  "/Users/fellow/VirtualBox VMs/Win10/Win10.vdi"  --compact *.vdi 路徑可以在 VirtualBox 儲...