Arduino - Ameba - 溫度計上雲端

example : https://github.com/neojou/arduino-ameba/tree/master/example/Xively

Ameba 總覽

另外新的 code 可以連 WPA-PSK (wep 還不行)
  WiFi1.begin(ssid) => 連沒有密碼的 AP
  WiFI1.begin(ssid, pass) => 連有密碼的 AP.

----

溫度計 : 使用 DHT22 (AM2302)

接法 :

DHT PIN1 Arduino 5V
DHT PIN2 10K Resistor Arduino 5V
DHT PIN2 Arduino Digital Pin 2
DHT PIN3 Not Used
DHT PIN4 Arduino GND
DHT22 Temperature and Humidity Sensor hookup


DHT class : DHT1.cpp(.h)
先暫時放在 cores 底下, 將來可以移出去放在 library


int read_temp(float *data)
{
      // READ DATA
    Serial.print("DHT22, \t");

    int ret = DHT.read22(DHT22_PIN);

    switch (ret)
    {
    case DHTLIB_OK:
        Serial.print("OK,\t");
        *data = (float)DHT.temperature;
        break;
    case DHTLIB_ERROR_CHECKSUM:
        Serial.print("Checksum error,\t");
        break;
    case DHTLIB_ERROR_TIMEOUT:
        Serial.print("Time out error,\t");
        break;
    default:
        Serial.print("Unknown error,\t");
        break;
    }
 
    // DISPLAY DATA
    Serial.print(DHT.humidity, 1);
    Serial.print(",\t");
    Serial.print(DHT.temperature, 1);
    Serial.print(",\t");
    Serial.println();

    return ret;
}

雲端的部分是參考 Xively

https://personal.xively.com/dev/tutorials/arduino_wi-fi/


- 註冊一個帳號 : 如果沒有可以點選 :  click here 
-  加入一個 device

加入後修正程式 :

#define xivelyFeed 667621444
這個改成你的 feed id :


char xivelyKey[] = "HlwyIaGp8Dic1WzmpJCFxg07zoj4DaWks9KKCfH21qKyeiro";

這改成中間看到的 API Keys. '





溫度上傳後, 瀏覽器上可以看到圖形

https://personal.xively.com/feeds/667621444



    八點公司冷氣開啟, 溫度掉下來..



uart log  如下, 可注意

 (1) 目前還只能先連 open 的,(AP 無密碼) ;  WPA-PSK 在 DHCP 上會卡住, 正在解決中.

(2) 底層程式連線會先做 scan , 找不到 AP 會秀兩行 scan_q is empty 停住.
      所以上層程式可以先寫 scan , scan 到再做 begin()
rtw_search_ssid_to_network: scan_q is empty
wl_search_ssid_to_network: dst_ssid=NeoTPLink, len=9, ndis_ssid=NeoTPLink, len = 9
rtw_search_ssid_to_network : Found

(3) 上層程式有個 delay 10 秒, 可以先縮短, 將來可能底層寫 semaphore 改進.

(4) 如果成功配到 IP, 會顯示 IP address.
IP Address: 192.168.0.101

=========================================================

Build Time: 2015/01/10-17:52:39
Build Author: root
Build Host: RTCN3192-P45V
Build ToolChain Version: gcc version 4.8.3 (Realtek ASDK-4.8.3p1 Build 2003)

=========================================================
TwoWire initializing
TwoWire initializing
rtw_init_sema : id = 0x100516f0
[TIMR Inf]us_ticker_init: Timer_Id=2
tcpip_init_done
HalData = 0x1003c720
Hal_EfuseParse: MAC = ec-f0-0e-39-74-bc
PackageType = 0x4
EEPRORFGainOffset = 0x00
rtw_init_timer dynamic_chk_timer :  0
Register Wlan DMA Interrupt
Using the default RF gain.
after rtw_hal_init, padapter=0x1003ab20
rtw_init_sema : id = 0x10051708
RTL8195A[HAL]: ISR 5 didb't bee register!!!
EnaEnter rtw_recv_threbleInterrupt8195a, ad, padapter=0x1003IntrMask[0][1][2]=3ab20
0, 7f, 0
EnableInterrupt8195a: enable DMA IMR=0x0000007F; Fw IME=0x00000030, WL PMC IMR=0x80000040
Starting single datastream upload to Xively...

rtw_init_sema : id = 0x10051720
rtw_search_ssid_to_network: scan_q is empty
wl_search_ssid_to_network: dst_ssid=NeoTPLink, len=9, ndis_ssid=NeoTPLink, len = 9
rtw_search_ssid_to_network : Found
 rtw_set_ssid Found!
 wl_wifi_connect : start to wOnAuthClient
thClient : auth sucent
cess, start assoc
OnAssocRsp
association success(res=1)

 rtw_joinbss_update_network  BSSID:30:b5:c2:89:29:6e
+rtw_update_ht_cap()
Set STA_(0) info
rtw_indicate_connect
WMM(0): 0,  wl_wifi_connect : a42b
WMM(1): 0, a4start to do dhcp
4f
WMM(2): 0, 5e43===================22
WMM(3): 0, 2f32===update_attrib: S22
HTOnAssocRsp
end DHCP Packet
connect successfully
Connected to wifi, delay 10 sec for DHCP
======================update_attrib: Send DHCP Packet
SSID: NeoTPLink
IP Address: 192.168.0.101
signal strength (RSSI):-31 dBm

dht22_test
Type,   status, Humidity (%),   Temperature (C) Time (us)
DHT22,  OK,     50.3,   28.4,
xivelyclient.put returned 200

留言

熱門文章