1.Hello world mBed
1.到mbed網站申請帳號
2.加入devivce
3.creat project
2.溫度sensor實驗
1.到Study spec
http://www.seeedstudio.com/wiki/index.php?title=Main_Page#Grove
http://www.seeedstudio.com/wiki/Grove_-_Starter_Kit_Plus
2.作法參考
https://www.mokoversity.com/workshop/mbed-school/02-gpio-introduction
3.加上四段顯示器
1.載入lib
https://developer.mbed.org/users/Seeed/code/DigitDisplay/
2.參考
https://developer.mbed.org/users/yihui/code/Arch_Digit_Display/file/89330707469d/main.cpp
4.上網
1.載入EthernetInterface這個lib,編譯時會發生error再載入mbed_rtos這個lib
2.再載入WebSocketClient這個lib
程式碼如下:
#include "mbed.h"
#include "DigitDisplay.h"
#include "EthernetInterface.h"
#include "Websocket.h"
AnalogIn temp(P0_23);
DigitalOut myled(LED1);
DigitalOut myled1(LED2);
DigitDisplay digdisp(P4_29,P4_28);
EthernetInterface eth;
int main() {
char data[1024];
float temperature;
float resistance;
int B=3975; //B value of the thermistor
int a;
int ret;
eth.init(); //DHCP
eth.connect();
Websocket ws("ws://wot.city/object/554ed61eae74407734000119/send");
ws.connect();
loop:
a=temp.read()*657;
resistance=(float)(1023-a)*10000/a; //get the resistance of the sensor;
temperature=1/(log(resistance/10000)/B+1/298.15)-273.15;//convert to temperature via datasheet
sprintf( data , "{ \"temperature\": %f }", temperature);
ret = ws.send(data);
myled1 = 1;
wait(0.5);
myled1 = 0;
wait(0.5);
goto loop;
}
3.到http://wotcity.com/申請帳號產生一個務間編號將他填到Websocket contruct之中
當裝置連線為live即可利用live App看到溫度數值
5.修改網頁
1.到http://wotcity.com/docs/dotcity-starter-kit下載網頁包
2.解壓縮照上面的步驟安裝函示庫
3.打開網址在網址後面輸入#554ed61eae74407734000119
即可看到溫度計的結果
沒有留言:
張貼留言