本帖最后由 聿怀嘿嘿 于 2015-1-12 21:29 编辑
( i {8 G8 h0 g& c
- ]# x/ j+ X" J5 [% z2 n. syeelink云平台是一个开放的通用物联网平台,主要提供传感器数据的接入、存储和展现服务,最重要的是对所有的软硬件爱好者是免费使用的!但yeelink SDK主要只做Arduino平台,之前自己用stm32库写了yeelink的上传程序、期间也因为不熟悉yeelink走了弯路、最后还是实现了功能,现在和大家一起共享!
' o! e# [: ^4 T) o8 x4 p% M. n3 z下面是上传gps类型的程序、输入参数是纬度、经度、速度
: C* |+ o4 ]0 A/ A2 f标红字体分别是你的设备id、传感器id和你的ApiKey,以下不再做解释哈;
8 y+ v7 \. i: \. B% n0 O0 I
4 U* U& P7 e2 w, Q$ ^7 F- int postgps (u32 lat,u32 lon,u16 speed)//6 I+ L( d) C7 e( ~4 X
- {float lattp,lontp,speedtp,tp;3 @& {8 f" S$ A4 ]
- lattp=lat;lontp=lon;speedtp=speed;( f; Q5 C2 W# r8 ? F7 r2 |9 G p
- int count=0;tp=speedtp/1000;
% N. O% E4 J% z( e - if(tp<100&tp>=10)
/ j" l& Q, C. u% X - {count=72;}
1 S$ d3 N9 A, o6 D9 s - else x3 N) T* g f& H
- {if(tp<10) count=71;8 {0 e: u) ^6 y- p
- else count=73;
6 T2 c% I* B. V* G# Q# G - }
% g' k t b6 t/ a - sprintf((char *)postGPS,"POST /v1.0/device/<font color="#ff0000">ddddd</font>/sensor/<font color="#ff0000">xxxxx</font>/datapoints HTTP/1.1\r\n"0 c4 I) H: |4 a. ~5 S3 n
- "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:9.0.1) Gecko/20100101 Firefox/9.0.1\r\n" ' P5 K# c# V+ ?
- "Host: api.yeelink.net\r\n"
4 i' g2 M; S; U2 y2 [ - "Accept: */*\r\n"5 k6 e/ ]& j9 A: i6 N7 E# q
- "U-ApiKey: <font color="#ff0000">xxx</font>\r\n"2 U; ]0 J k- j1 {0 F
- "Content-Length: %02d\r\n"% h0 t4 Y5 M" I0 Z4 q V
- "Content-Type: application/x-www-form-urlencoded\r\n"9 T5 v9 E: a# n& G1 P
- "\r\n"
5 j7 _/ E2 Y$ i3 P2 q - "{"value":{"lat":%.5f,"lng":%.5f,"speed":%.3f,"offset":"yes"}}\r\n",count,lattp/=100000,lontp/=100000,speedtp/=1000);5 G7 ~4 c- A8 a5 L
- 2 c3 y9 p! D$ a
- return strlen(postGPS);
复制代码 下面是数据点类型的程序8 k5 t/ W |. f: {1 F" Z
2 t3 h& h0 n# S3 ~# X$ H$ u
输入参数是 你的数据。/ L4 R# K. F! ^* V5 v
- int posthigh (int altitude)
! T% F8 e8 j, b - {float alttp,tp;
! s* x/ J' m! @* V$ i+ K - alttp=altitude;' A4 H% o. \# l' P/ u4 H9 e2 o
- int count=0;tp=alttp/10;, I! h1 N( {/ f4 X+ m( @
- if(tp<100&tp>=10)
V+ O' ~% Y0 u( ?" h: U; ?. L - {count=15;}
3 s" y$ c. h& J& K. L$ a# e* B - else : o& m/ t3 P9 }% v
- {if(tp<10) count=14;, A4 V1 C" m. `* } e: ?7 I
- else count=16;
4 \) l' B+ f: D, L+ }) N - } 8 o V& m/ f; i3 d& Q/ r# y; X
- sprintf((char *)postHIGH,"POST /v1.0/device/<font color="#ff0000">ddddd</font>/sensor/<font color="#ff0000">xxxxx</font>/datapoints HTTP/1.1\r\n"* X5 s! q; o5 Y6 e
- "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:9.0.1) Gecko/20100101 Firefox/9.0.1\r\n"
" c8 l- W w5 p* `9 A2 Y - "Host: api.yeelink.net\r\n": D9 K8 J/ W C- L) a
- "Accept: */*\r\n"
" S+ T% @3 P- k( J - "U-ApiKey:<font color="#ff0000">xxx</font>\r\n"9 N% |5 V9 a- j0 ~: }+ r
- "Content-Length: %02d\r\n"
3 Q; o: v1 B9 G2 l - "Content-Type: application/x-www-form-urlencoded\r\n"/ f$ k2 P [. |' U3 ^+ Y# K6 R* E
- "\r\n"1 B; s$ T- B. N& F9 \; X# {/ S
- "{"value":%.2f}\r\n",count,alttp/=10);6 p6 q$ B) W7 K: |( ]$ \7 q
- % X6 z) z7 i6 P
- return strlen(postHIGH);
% N0 E1 \: P' f P - }
复制代码 下面是开关类型的数据) G- }% h$ \" H
- int postswitch(int switch0)! v, [& m4 G+ N( [
- {7 F; l( V2 t! b7 ^) k
- sprintf((char *)postSWITCH0,"POST /v1.0/device/<font color="#ff0000">ddddd</font>/sensor/<font color="#ff0000">xxxxx</font>/datapoints HTTP/1.1\r\n"
+ g: x7 D) p0 o: n( I: J - "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:9.0.1) Gecko/20100101 Firefox/9.0.1\r\n" 3 q; q+ g5 x, M/ I' H
- "Host: api.yeelink.net\r\n"" a# {9 }$ f# K' I3 Z
- "Accept: */*\r\n"* s/ p, N: @& {3 Q
- "U-ApiKey: <font color="#ff0000">xxx</font>\r\n", e5 l0 m9 r4 n/ U* B
- "Content-Length: 11\r\n"
: P; V3 }; K7 e6 H2 z" o - "Content-Type: application/x-www-form-urlencoded\r\n"
+ b: F& [( X0 Q% @ - "\r\n"
+ p w) s P: i: _0 r- p0 k - "{"value":%01d}\r\n",switch0);) [5 q$ D+ K% Z( d' d$ l! L" q
y4 T0 _, h/ q. [' @7 R+ f, Y- return strlen(postSWITCH0);
1 C5 J$ a, m# d% v' w - }
复制代码 很小白,大神轻喷哈!
3 p0 p# V- L0 [" x% M
yeelink.zip
(1.36 KB, 下载次数: 209)
|
yeelink官方已经开发了app、支持安卓和ios系统的
谢谢哈哈
我不需要他的,我希望用我自己的APP,可以的吗?
理论上可以、他的api接口是开放的、
免费使用?
嗯、对于个人是