当前位置: 首页>>代码示例>>C++>>正文


C++ JsonObject::printTo方法代码示例

本文整理汇总了C++中JsonObject::printTo方法的典型用法代码示例。如果您正苦于以下问题:C++ JsonObject::printTo方法的具体用法?C++ JsonObject::printTo怎么用?C++ JsonObject::printTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在JsonObject的用法示例。


在下文中一共展示了JsonObject::printTo方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: sendMessage

int transportMgr::sendMessage(WiFiClient socket,JsonObject&  sendMsg)
{
#if 0
	long length=0;
	String header=String(PACKET_MAGIC);
	length=sendMsg.printTo(Serial);
	if(length>999)		header=header+length;
	else if(length>99)	header=header+"0"+length;
	else if(length>9)	header=header+"00"+length;
	else 				header=header+"000"+length;
	socket.print(header);
	sendMsg.printTo(socket);
	sendMsg.printTo(Serial);
	//Serial.println(".....................");
	
#else
	char bufHeader[20];
	long length=sendMsg.printTo(Serial);
	sprintf(bufHeader,"%s%08d",PACKET_MAGIC,length);
	socket.print(bufHeader);
	sendMsg.printTo(socket);
	Serial.println("sent!");
	//socket.print("{\"messageType\":\"configuableTime\",\"configuableType\":\"light\",\"time\":\"40\"}\n");
	//Serial.println("sent!!");
	
	
#endif
}
开发者ID:Youngsoo,项目名称:iot-platform,代码行数:28,代码来源:transport.cpp

示例2: postJson

bool WebServiceFSM::postJson(JsonObject& msg) {
  // .printTo stupidly writes a '\0' in its last position, so any destination
  // printed to must ask for one more than the strlen of the JSON.
  char to_server[MAX_MSG_SIZE];
  msg.printTo(to_server, 1+msg.measureLength());
  curl_easy_setopt(curl, CURLOPT_POSTFIELDS, to_server);

  char from_server[MAX_MSG_SIZE];
  auto fin = fmemopen(from_server, MAX_MSG_SIZE, "w");

  curl_easy_setopt(curl, CURLOPT_WRITEDATA, fin);

  res = curl_easy_perform(curl);
  fclose(fin);

  // Check for errors
  if(res != CURLE_OK) {
    fprintf(stderr, "WebQ: Failed to access %s: %s\n", "localhost",
        curl_easy_strerror(res));
  }
  else {
    fprintf(stderr, "WebQ: Connection successful, received '%s'\n", from_server);
  }

  return res == CURLE_OK;
}
开发者ID:netguy204,项目名称:swarm-mothership,代码行数:26,代码来源:wsfsm.cpp

示例3: putJson

bool WebServiceFSM::putJson(JsonObject& msg) {
  // .printTo stupidly writes a '\0' in its last position, so any destination
  // printed to must ask for one more than the strlen of the JSON.  At the
  // other end of the connection, Node.js will choke on PUT data if you throw a
  // null byte at it.  So, the FILE* must be as large as the JSON string, not
  // counting the null byte.
  // I place the primary blame on ArduinoJson for this one.  Honte, Benoit!
  char to_server[MAX_MSG_SIZE];
  msg.printTo(to_server, 1+msg.measureLength());
  auto fout = fmemopen(to_server, msg.measureLength(), "r");

  curl_easy_setopt(curl, CURLOPT_UPLOAD, 1);
  curl_easy_setopt(curl, CURLOPT_READDATA, fout);

  char from_server[MAX_MSG_SIZE];
  auto fin = fmemopen(from_server, MAX_MSG_SIZE, "w");
  curl_easy_setopt(curl, CURLOPT_WRITEDATA, fin);

  res = curl_easy_perform(curl);
  fclose(fin);
  fclose(fout);
  // Turn off PUT mode
  curl_easy_setopt(curl, CURLOPT_UPLOAD, 0);

  // Check for errors
  if(res != CURLE_OK) {
    fprintf(stderr, "WebQ: Failed to access %s: %s\n", "localhost",
        curl_easy_strerror(res));
  }
  else {
    fprintf(stderr, "WebQ: Connection successful, received '%s'\n", from_server);
  }

  return res == CURLE_OK;
}
开发者ID:netguy204,项目名称:swarm-mothership,代码行数:35,代码来源:wsfsm.cpp

示例4: sendMessage

int transportMgr::sendMessage(WiFiClient socket,JsonObject&  sendMsg)
{
#if 0
	long length=0;
	String header=String(PACKET_MAGIC);
	length=sendMsg.printTo(Serial);
	if(length>999)		header=header+length;
	else if(length>99)	header=header+"0"+length;
	else if(length>9)	header=header+"00"+length;
	else 				header=header+"000"+length;
	socket.print(header);
	sendMsg.printTo(socket);
	sendMsg.printTo(Serial);
	//Serial.println(".....................");
	
#else
	char bufHeader[20];
	long length=sendMsg.printTo(Serial);
	sprintf(bufHeader,"%s%04d",PACKET_MAGIC,length);
	socket.print(bufHeader);
	sendMsg.printTo(socket);
	
#endif
}
开发者ID:caocf,项目名称:iot-platform,代码行数:24,代码来源:transport.cpp

示例5: sendTriggerEventWithData

String IFTTTMaker::sendTriggerEventWithData(String eventName, JsonObject& payload) {
	String response="";
  bool finishedHeaders = false;
  bool currentLineIsBlank = true;
	long now;
	bool avail;
	// Connect with IFTTT
	if (client->connect(HOST, SSL_PORT)) {
		//Serial.println(".... connected to server");
		String a="";
		char c;
		int ch_count=0;
		client->print("POST /trigger/"+eventName+"/with/key/"+_key);
    client->println(" HTTP/1.1");
    // Host header
    client->print("Host:"); client->println(HOST);
    // JSON content type
    client->println("Content-Type: application/json");
    // Content length
    int length = payload.measureLength();
    client->print("Content-Length:"); client->println(length);
    // End of headers
    client->println();
    // POST message body
    String out;
    payload.printTo(out);
    //Serial.println(out);
    client->println(out);

    now=millis();
		avail=false;
    //Serial.println("starting timer");
		while (millis()-now<1500) {
			while (client->available()) {
				char c = client->read();
				//Serial.print(c);
        response = response + c;
			}
		}
	}

  //Serial.println("response");
  //Serial.println(response);
  return response;
}
开发者ID:trendy77,项目名称:TSMARTPad,代码行数:45,代码来源:IFTTTMaker.cpp

示例6: sendResponse

void sendResponse(int status, JsonObject &content) {
  String responseString;
  content.printTo(responseString);
  sendResponse(status, responseString);
}
开发者ID:grappendorf,项目名称:signal-tower,代码行数:5,代码来源:main.cpp


注:本文中的JsonObject::printTo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。