SaveUserInfoRequest::SaveUserInfoRequest(UserInfo &info) : APIRequest(SCHEME SERVER "/Profile.json") { AddPostData({ { "Location", info.location.ToUtf8() }, { "Biography", info.biography.ToUtf8() } }); }
/***************************************************************************** * * Cloud_Post * * \param pbuf - string buffer containing data to be sent * bufsize - number of bytes to send * * \return 1 success; 0 failure * * \brief Writes data to Exosite cloud * *****************************************************************************/ int Cloud_Post() { int length; char DataLen[10]; // int http_status = 0; char *cmp_ss = "Content-Length:"; char *cmp = cmp_ss; DWORD serverip = 0; const unsigned char server[6] = SERVERIP ; serverip = (server[3] << 24 & 0xff000000) | (server[2] << 16 & 0xff0000) | (server[1] << 8 & 0xff00) | (server[0] & 0xff); long w, r; char rev[300]; unsigned char len; char *p; unsigned char crlf = 0; int time_out = 0; int tx_buff_size = 250; int tmp_len =0 ; if(status_code == STATUS_INIT||status_code == STATUS_END){ if (sock == INVALID_SOCKET) { sock = TCPOpen(serverip, TCP_OPEN_IP_ADDRESS, HTTP_PORT, TCP_PURPOSE_TCP_CLIENT); // TCP_OPEN_RAM_HOST for using dns name as server name // TCPOpen(serverip, TCP_OPEN_IP_ADDRESS, server_port, TCP_PURPOSE_GENERIC_TCP_CLIENT); if (sock == INVALID_SOCKET) { status_code = STATUS_INIT; // LEDS_OFF(); // LEDS_ON(); return 0; } status_code = STATUS_READY; } else status_code == STATUS_READY; } else if(status_code == STATUS_READY) { if(sent_header) DelayMs(20); w = TCPIsPutReady(sock); if(w<=250ul) { return 0; } if(sent_header){ memset(header, 0, sizeof(header)); length = PostHeaderGenerate("/rcvdata.php", cmd_no, (int) start_time, (int) end_time); length = PostHeaderUpdateLength(length, MAXSENSORDATASIZE, 2); remain_count =0 ; sent_header = FALSE; sent_count = 0; } else { if(tx_buffer_clear) { memset(header, 0, sizeof(header)); int tx_num = MAXSENSORDATASIZE - sent_count; tx_num = tx_num>=125? 125:tx_num; AddPostData(sent_count, tx_num); // memset(header, 65, 250); remain_count =0 ; sent_count +=tx_num; } } // LED2_ON(); LED1_OFF(); int send_len = strlen(&header[remain_count]); // LED2_ON(); LED1_OFF(); //if(send_len > 254) {LED2_ON(); LED1_OFF()}; /* The max size of sliding window for TCP packet is 254? after testing. * Don't know the reason, but if we set the number of sending data to 250, * the program works fine. * */ tmp_len = send_len>250? 250:send_len; // int tmp_len = IHMS_SocketSend(sock, &header[sent_count], send_len ); tmp_len = TCPPutArray(sock, (BYTE *) &header[remain_count], tmp_len); TCPFlush((TCP_SOCKET)sock); LED2_ON(); LED1_OFF(); if(tmp_len<send_len) { remain_count += tmp_len; tx_buffer_clear = FALSE; return 0; } remain_count = 0; tx_buffer_clear = TRUE; if(sent_count<MAXSENSORDATASIZE) return 0 ; memset(header, 0, sizeof(header)); sent_count = 0; remain_count = 0; status_code = STATUS_RCV; } else if(status_code == STATUS_RCV) { DelayMs(20); r = TCPIsGetReady((TCP_SOCKET) sock); if(r<200u){ LED2_ON(); return 0;} // now read all data in RX buffer int count = 0; do { r = TCPGetArray((TCP_SOCKET)sock, (BYTE *)&rev[count], 300); count = count + r; rev[count]=0; r = TCPIsGetReady((TCP_SOCKET) sock); }while(r>0u); rev[count] = 0 ; TCPClose((TCP_SOCKET)sock); status_code = STATUS_END; sock = INVALID_SOCKET; status_code = STATUS_END; sent_header = TRUE; //now it's time to read time GetServerCmd(rev, "cmd="); cmd_no = GetServerCmd(rev, "no="); DelayMs(100); return 1; } return 0; }
void Download::AddPostData(std::pair<std::string, std::string> data) { std::map<std::string, std::string> postData; postData.insert(data); AddPostData(postData); }