Use ESP8266 to connect ThingSpeak.com
Drive to connect with ThingSpeak.com,
it`s work well, but it don`t provided return message
you can send "int" "float" "char".
ESP8266和ThingSpeak.com的驱动,工作正常,但是驱动不提供ESP8266的返回消息
ThingSpeak_ESP8266.h@1:6df8ccaec251, 2019-02-14 (annotated)
- Committer:
- Yifan_Du
- Date:
- Thu Feb 14 08:00:22 2019 +0000
- Revision:
- 1:6df8ccaec251
- Parent:
- 0:1432a364e32a
Delete personal information
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Yifan_Du | 0:1432a364e32a | 1 | /* |
Yifan_Du | 0:1432a364e32a | 2 | Copyright (c) 2019 Yifan DU |
Yifan_Du | 0:1432a364e32a | 3 | |
Yifan_Du | 0:1432a364e32a | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy |
Yifan_Du | 0:1432a364e32a | 5 | of this software and associated documentation files (the "Software"), to deal |
Yifan_Du | 0:1432a364e32a | 6 | in the Software without restriction, including without limitation the rights |
Yifan_Du | 0:1432a364e32a | 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
Yifan_Du | 0:1432a364e32a | 8 | copies of the Software, and to permit persons to whom the Software is |
Yifan_Du | 0:1432a364e32a | 9 | furnished to do so, subject to the following conditions: |
Yifan_Du | 0:1432a364e32a | 10 | |
Yifan_Du | 0:1432a364e32a | 11 | The above copyright notice and this permission notice shall be included in |
Yifan_Du | 0:1432a364e32a | 12 | all copies or substantial portions of the Software. |
Yifan_Du | 0:1432a364e32a | 13 | |
Yifan_Du | 0:1432a364e32a | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
Yifan_Du | 0:1432a364e32a | 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
Yifan_Du | 0:1432a364e32a | 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
Yifan_Du | 0:1432a364e32a | 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
Yifan_Du | 0:1432a364e32a | 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
Yifan_Du | 0:1432a364e32a | 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
Yifan_Du | 0:1432a364e32a | 20 | THE SOFTWARE. |
Yifan_Du | 0:1432a364e32a | 21 | |
Yifan_Du | 0:1432a364e32a | 22 | |
Yifan_Du | 0:1432a364e32a | 23 | 1.0 14-Feb.-2019 - Initial release. |
Yifan_Du | 0:1432a364e32a | 24 | |
Yifan_Du | 0:1432a364e32a | 25 | ***************************************************************** |
Yifan_Du | 0:1432a364e32a | 26 | Attention: This drive don not have response |
Yifan_Du | 0:1432a364e32a | 27 | ***************************************************************** |
Yifan_Du | 0:1432a364e32a | 28 | @code |
Yifan_Du | 0:1432a364e32a | 29 | |
Yifan_Du | 0:1432a364e32a | 30 | #include "mbed.h" |
Yifan_Du | 0:1432a364e32a | 31 | #include "ThingSpeak_ESP8266.h" |
Yifan_Du | 0:1432a364e32a | 32 | |
Yifan_Du | 0:1432a364e32a | 33 | #define SSID "YOUR API_KEY" |
Yifan_Du | 0:1432a364e32a | 34 | #define Password "WIFI SSID" |
Yifan_Du | 0:1432a364e32a | 35 | #define API_Key "WIFI PASSWORD" |
Yifan_Du | 0:1432a364e32a | 36 | |
Yifan_Du | 0:1432a364e32a | 37 | Serial PC(USBTX, USBRX, 115200); |
Yifan_Du | 0:1432a364e32a | 38 | ESP8266 WIFI(PC_10, PC_11, 115200); |
Yifan_Du | 0:1432a364e32a | 39 | |
Yifan_Du | 0:1432a364e32a | 40 | void WIFI_init(void) |
Yifan_Du | 0:1432a364e32a | 41 | { |
Yifan_Du | 0:1432a364e32a | 42 | printf("\r\nReset ESP..."); |
Yifan_Du | 0:1432a364e32a | 43 | WIFI.Reset(); |
Yifan_Du | 0:1432a364e32a | 44 | |
Yifan_Du | 0:1432a364e32a | 45 | printf("\r\nSet Mode..."); |
Yifan_Du | 0:1432a364e32a | 46 | WIFI.Set_Mode(); |
Yifan_Du | 0:1432a364e32a | 47 | |
Yifan_Du | 0:1432a364e32a | 48 | printf("\r\nConnect WIFI...."); |
Yifan_Du | 0:1432a364e32a | 49 | WIFI.Connect_WIFI(SSID, Password); |
Yifan_Du | 0:1432a364e32a | 50 | } |
Yifan_Du | 0:1432a364e32a | 51 | |
Yifan_Du | 0:1432a364e32a | 52 | int main(void) |
Yifan_Du | 0:1432a364e32a | 53 | { |
Yifan_Du | 0:1432a364e32a | 54 | int data = 0; |
Yifan_Du | 0:1432a364e32a | 55 | |
Yifan_Du | 0:1432a364e32a | 56 | WIFI_init(); |
Yifan_Du | 0:1432a364e32a | 57 | WIFI.User_API_Key = API_Key; |
Yifan_Du | 0:1432a364e32a | 58 | |
Yifan_Du | 0:1432a364e32a | 59 | while(1) |
Yifan_Du | 0:1432a364e32a | 60 | { |
Yifan_Du | 0:1432a364e32a | 61 | PC.printf("Send %2d", data); |
Yifan_Du | 0:1432a364e32a | 62 | WIFI.Send_To_ThingSpeak_int(1, data); |
Yifan_Du | 0:1432a364e32a | 63 | PC.printf(" Done\r\n"); |
Yifan_Du | 0:1432a364e32a | 64 | |
Yifan_Du | 0:1432a364e32a | 65 | data++; |
Yifan_Du | 0:1432a364e32a | 66 | wait(5); |
Yifan_Du | 0:1432a364e32a | 67 | } |
Yifan_Du | 0:1432a364e32a | 68 | } |
Yifan_Du | 0:1432a364e32a | 69 | |
Yifan_Du | 0:1432a364e32a | 70 | @endcode |
Yifan_Du | 0:1432a364e32a | 71 | ***************************************************************** |
Yifan_Du | 0:1432a364e32a | 72 | */ |
Yifan_Du | 0:1432a364e32a | 73 | |
Yifan_Du | 0:1432a364e32a | 74 | #ifndef _THINGSPEAK_ESP8266_H_ |
Yifan_Du | 0:1432a364e32a | 75 | #define _THINGSPEAK_ESP8266_H_ |
Yifan_Du | 0:1432a364e32a | 76 | |
Yifan_Du | 0:1432a364e32a | 77 | #include "mbed.h" |
Yifan_Du | 0:1432a364e32a | 78 | |
Yifan_Du | 0:1432a364e32a | 79 | class ESP8266 |
Yifan_Du | 0:1432a364e32a | 80 | { |
Yifan_Du | 0:1432a364e32a | 81 | public: |
Yifan_Du | 0:1432a364e32a | 82 | char* User_API_Key; |
Yifan_Du | 0:1432a364e32a | 83 | |
Yifan_Du | 0:1432a364e32a | 84 | ESP8266(PinName ESP_TX, PinName ESP_RX, int ESP_BR); |
Yifan_Du | 0:1432a364e32a | 85 | |
Yifan_Du | 0:1432a364e32a | 86 | void Reset(void); |
Yifan_Du | 0:1432a364e32a | 87 | |
Yifan_Du | 0:1432a364e32a | 88 | void Set_Mode(void); |
Yifan_Du | 0:1432a364e32a | 89 | |
Yifan_Du | 0:1432a364e32a | 90 | void Connect_WIFI(char *WIFI_SSID, char *WIFI_Password); |
Yifan_Du | 0:1432a364e32a | 91 | |
Yifan_Du | 0:1432a364e32a | 92 | void Send_To_ThingSpeak_int(int field, int Data); |
Yifan_Du | 0:1432a364e32a | 93 | |
Yifan_Du | 0:1432a364e32a | 94 | void Send_To_ThingSpeak_float(int field, float Data); |
Yifan_Du | 0:1432a364e32a | 95 | |
Yifan_Du | 0:1432a364e32a | 96 | void Send_To_ThingSpeak_char(int field, char* Data); |
Yifan_Du | 0:1432a364e32a | 97 | |
Yifan_Du | 0:1432a364e32a | 98 | bool Is_Success(void); |
Yifan_Du | 0:1432a364e32a | 99 | |
Yifan_Du | 0:1432a364e32a | 100 | private: |
Yifan_Du | 0:1432a364e32a | 101 | Serial ESP; |
Yifan_Du | 0:1432a364e32a | 102 | char* ESP_Cmd; |
Yifan_Du | 0:1432a364e32a | 103 | char URL[300]; |
Yifan_Du | 0:1432a364e32a | 104 | }; |
Yifan_Du | 0:1432a364e32a | 105 | |
Yifan_Du | 0:1432a364e32a | 106 | #endif |