![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
init
Fork of 仓库 by
main.cpp@1:3b487c4813a2, 2017-11-07 (annotated)
- Committer:
- zhangyx
- Date:
- Tue Nov 07 03:15:44 2017 +0000
- Revision:
- 1:3b487c4813a2
- Parent:
- 0:63af4719467f
- Child:
- 2:b10925c474fc
new class interface
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
brainliang | 0:63af4719467f | 1 | /*----------------------------------------------------- |
brainliang | 0:63af4719467f | 2 | File Name : main.cpp |
brainliang | 0:63af4719467f | 3 | Purpose : For esp8266 mbed porting |
brainliang | 0:63af4719467f | 4 | Creation Date : 22-06-2017 |
brainliang | 0:63af4719467f | 5 | Last Modified : |
brainliang | 0:63af4719467f | 6 | Created By : Jeasine Ma [jeasinema[at]gmail[dot]com] |
brainliang | 0:63af4719467f | 7 | -----------------------------------------------------*/ |
brainliang | 0:63af4719467f | 8 | #include <cstdarg> |
brainliang | 0:63af4719467f | 9 | #include <cstring> |
brainliang | 0:63af4719467f | 10 | #include "mbed.h" |
brainliang | 0:63af4719467f | 11 | #include "esp8266.h" |
brainliang | 0:63af4719467f | 12 | |
brainliang | 0:63af4719467f | 13 | |
brainliang | 0:63af4719467f | 14 | Serial ser2usb(USBTX, USBRX); |
brainliang | 0:63af4719467f | 15 | |
brainliang | 0:63af4719467f | 16 | int main(void) { |
zhangyx | 1:3b487c4813a2 | 17 | // 选定与 esp8266 相连接的串口,WiFi 名称和密码 |
zhangyx | 1:3b487c4813a2 | 18 | // 参数分别为 TX pin / RX pin / SSID / Password |
zhangyx | 1:3b487c4813a2 | 19 | Esp8266 client(PC_10, PC_11, "TSINGHUA.iCenter", "TS.icenter"); |
brainliang | 0:63af4719467f | 20 | client.connect_mqtt_broker("tdxls-iot.xicp.net"); |
brainliang | 0:63af4719467f | 21 | ser2usb.printf("Initialization done.\r\n"); |
brainliang | 0:63af4719467f | 22 | |
brainliang | 0:63af4719467f | 23 | while(1) { |
brainliang | 0:63af4719467f | 24 | client.publish("/smartcar", "awesome smartcar!"); |
brainliang | 0:63af4719467f | 25 | client.publish("/smartcar", "awesome smartcar!"); |
brainliang | 0:63af4719467f | 26 | wait(1); |
brainliang | 0:63af4719467f | 27 | //char buf[32]; |
brainliang | 0:63af4719467f | 28 | //client.subscribe_poll("/icenter", buf, 32); |
brainliang | 0:63af4719467f | 29 | //ser2esp8266.attach(simple_callback, Serial::RxIrq); |
brainliang | 0:63af4719467f | 30 | //ser2usb.printf("%s\r\n", esp_paramBuf); |
brainliang | 0:63af4719467f | 31 | //ser2usb.printf("loop\r\n"); |
brainliang | 0:63af4719467f | 32 | //ser2usb.printf("haha\n"); |
brainliang | 0:63af4719467f | 33 | //while(1); |
brainliang | 0:63af4719467f | 34 | } |
brainliang | 0:63af4719467f | 35 | } |