温度センサLM75BとWi-FiモジュールESP-WROOM-02をmbed LPC1114FN28に繋げて、温度をIFTTTのMaker Channelに出力するプログラム

Dependencies:   LM75B mbed

Committer:
jksoft
Date:
Sun May 15 11:47:02 2016 +0000
Revision:
0:53a512d5a7ba
??

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jksoft 0:53a512d5a7ba 1 /* HTTPText.cpp */
jksoft 0:53a512d5a7ba 2 /* Copyright (C) 2012 mbed.org, MIT License
jksoft 0:53a512d5a7ba 3 *
jksoft 0:53a512d5a7ba 4 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
jksoft 0:53a512d5a7ba 5 * and associated documentation files (the "Software"), to deal in the Software without restriction,
jksoft 0:53a512d5a7ba 6 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
jksoft 0:53a512d5a7ba 7 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
jksoft 0:53a512d5a7ba 8 * furnished to do so, subject to the following conditions:
jksoft 0:53a512d5a7ba 9 *
jksoft 0:53a512d5a7ba 10 * The above copyright notice and this permission notice shall be included in all copies or
jksoft 0:53a512d5a7ba 11 * substantial portions of the Software.
jksoft 0:53a512d5a7ba 12 *
jksoft 0:53a512d5a7ba 13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
jksoft 0:53a512d5a7ba 14 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
jksoft 0:53a512d5a7ba 15 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
jksoft 0:53a512d5a7ba 16 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
jksoft 0:53a512d5a7ba 17 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
jksoft 0:53a512d5a7ba 18 */
jksoft 0:53a512d5a7ba 19
jksoft 0:53a512d5a7ba 20 #include "HTTPText.h"
jksoft 0:53a512d5a7ba 21
jksoft 0:53a512d5a7ba 22 #include <cstring>
jksoft 0:53a512d5a7ba 23
jksoft 0:53a512d5a7ba 24 #define OK 0
jksoft 0:53a512d5a7ba 25
jksoft 0:53a512d5a7ba 26 using std::memcpy;
jksoft 0:53a512d5a7ba 27 using std::strncpy;
jksoft 0:53a512d5a7ba 28 using std::strlen;
jksoft 0:53a512d5a7ba 29
jksoft 0:53a512d5a7ba 30 #define MIN(x,y) (((x)<(y))?(x):(y))
jksoft 0:53a512d5a7ba 31
jksoft 0:53a512d5a7ba 32 HTTPText::HTTPText(char* str) : m_str(str), m_pos(0)
jksoft 0:53a512d5a7ba 33 {
jksoft 0:53a512d5a7ba 34 m_size = strlen(str) + 1;
jksoft 0:53a512d5a7ba 35 }
jksoft 0:53a512d5a7ba 36
jksoft 0:53a512d5a7ba 37 HTTPText::HTTPText(char* str, size_t size) : m_str(str), m_size(size), m_pos(0)
jksoft 0:53a512d5a7ba 38 {
jksoft 0:53a512d5a7ba 39
jksoft 0:53a512d5a7ba 40 }
jksoft 0:53a512d5a7ba 41
jksoft 0:53a512d5a7ba 42 //IHTTPDataIn
jksoft 0:53a512d5a7ba 43 /*virtual*/ void HTTPText::readReset()
jksoft 0:53a512d5a7ba 44 {
jksoft 0:53a512d5a7ba 45 m_pos = 0;
jksoft 0:53a512d5a7ba 46 }
jksoft 0:53a512d5a7ba 47
jksoft 0:53a512d5a7ba 48 /*virtual*/ int HTTPText::read(char* buf, size_t len, size_t* pReadLen)
jksoft 0:53a512d5a7ba 49 {
jksoft 0:53a512d5a7ba 50 *pReadLen = MIN(len, m_size - 1 - m_pos);
jksoft 0:53a512d5a7ba 51 memcpy(buf, m_str + m_pos, *pReadLen);
jksoft 0:53a512d5a7ba 52 m_pos += *pReadLen;
jksoft 0:53a512d5a7ba 53 return OK;
jksoft 0:53a512d5a7ba 54 }
jksoft 0:53a512d5a7ba 55
jksoft 0:53a512d5a7ba 56 /*virtual*/ int HTTPText::getDataType(char* type, size_t maxTypeLen) //Internet media type for Content-Type header
jksoft 0:53a512d5a7ba 57 {
jksoft 0:53a512d5a7ba 58 #if 1
jksoft 0:53a512d5a7ba 59 strncpy(type, "application/json", maxTypeLen-1);
jksoft 0:53a512d5a7ba 60 #else
jksoft 0:53a512d5a7ba 61 strncpy(type, "text/plain", maxTypeLen-1);
jksoft 0:53a512d5a7ba 62 #endif
jksoft 0:53a512d5a7ba 63 type[maxTypeLen-1] = '\0';
jksoft 0:53a512d5a7ba 64 return OK;
jksoft 0:53a512d5a7ba 65 }
jksoft 0:53a512d5a7ba 66
jksoft 0:53a512d5a7ba 67 /*virtual*/ bool HTTPText::getIsChunked() //For Transfer-Encoding header
jksoft 0:53a512d5a7ba 68 {
jksoft 0:53a512d5a7ba 69 return false;
jksoft 0:53a512d5a7ba 70 }
jksoft 0:53a512d5a7ba 71
jksoft 0:53a512d5a7ba 72 /*virtual*/ size_t HTTPText::getDataLen() //For Content-Length header
jksoft 0:53a512d5a7ba 73 {
jksoft 0:53a512d5a7ba 74 return m_size - 1;
jksoft 0:53a512d5a7ba 75 }
jksoft 0:53a512d5a7ba 76
jksoft 0:53a512d5a7ba 77 //IHTTPDataOut
jksoft 0:53a512d5a7ba 78 /*virtual*/ void HTTPText::writeReset()
jksoft 0:53a512d5a7ba 79 {
jksoft 0:53a512d5a7ba 80 m_pos = 0;
jksoft 0:53a512d5a7ba 81 }
jksoft 0:53a512d5a7ba 82
jksoft 0:53a512d5a7ba 83 /*virtual*/ int HTTPText::write(const char* buf, size_t len)
jksoft 0:53a512d5a7ba 84 {
jksoft 0:53a512d5a7ba 85 size_t writeLen = MIN(len, m_size - 1 - m_pos);
jksoft 0:53a512d5a7ba 86 memcpy(m_str + m_pos, buf, writeLen);
jksoft 0:53a512d5a7ba 87 m_pos += writeLen;
jksoft 0:53a512d5a7ba 88 m_str[m_pos] = '\0';
jksoft 0:53a512d5a7ba 89 return OK;
jksoft 0:53a512d5a7ba 90 }
jksoft 0:53a512d5a7ba 91
jksoft 0:53a512d5a7ba 92 /*virtual*/ void HTTPText::setDataType(const char* type) //Internet media type from Content-Type header
jksoft 0:53a512d5a7ba 93 {
jksoft 0:53a512d5a7ba 94
jksoft 0:53a512d5a7ba 95 }
jksoft 0:53a512d5a7ba 96
jksoft 0:53a512d5a7ba 97 /*virtual*/ void HTTPText::setIsChunked(bool chunked) //From Transfer-Encoding header
jksoft 0:53a512d5a7ba 98 {
jksoft 0:53a512d5a7ba 99
jksoft 0:53a512d5a7ba 100 }
jksoft 0:53a512d5a7ba 101
jksoft 0:53a512d5a7ba 102 /*virtual*/ void HTTPText::setDataLen(size_t len) //From Content-Length header, or if the transfer is chunked, next chunk length
jksoft 0:53a512d5a7ba 103 {
jksoft 0:53a512d5a7ba 104
jksoft 0:53a512d5a7ba 105 }
jksoft 0:53a512d5a7ba 106
jksoft 0:53a512d5a7ba 107
jksoft 0:53a512d5a7ba 108