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


C++ StaticJsonBuffer::createObject方法代码示例

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


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

示例1: addAsset

void Device::addAsset(const char *name, const AssetType type, const char *profileType) const {
  StaticJsonBuffer<128> jsonBuffer;
  JsonObject &profile = jsonBuffer.createObject();
  JsonObject &root = jsonBuffer.createObject();

  root["title"] = name;
  root["is"] = assetTypeToString(type);
  profile["type"] = profileType;
  root["profile"] = profile;

  char url[64];
  char header[128];
  char body[128];

  root.printTo(body, sizeof(body));
  int contentLength = strlen(body);

  // We're authorizing using Auth-ClientId and Auth-ClientKey headers on /device/:id/asset/:name URI
  sprintf(header, "Auth-ClientId: %s\r\nAuth-ClientKey: %s\r\nContent-Length: %d\r\n", _clientId, _clientKey, contentLength);
  sprintf(url, "/device/%s/asset/%s", _deviceId, name);

  char resp[1024];
  _rest.setHeader(header);
  _rest.put(url, body);

  // dump response for debugging purposes, you can turn this off
  _rest.getResponse(resp, sizeof(resp));
  LOG(resp);
}
开发者ID:rayalex,项目名称:smartliving-weather-station,代码行数:29,代码来源:device.cpp

示例2: migrate

bool KeyValueStore::migrate() {
  if (!SPIFFS.exists(FILENAME_OLD)) {
    return true;
  }
  StaticJsonBuffer<300> jsonBuffer;
  JsonObject& root = jsonBuffer.createObject();

  File f = SPIFFS.open(FILENAME_OLD, "r");
  if (!f) {
    return false;
  }
  while(f.available()) {
    String line = f.readStringUntil('\n');
    int separator = line.indexOf("=");
    if (separator > -1) {
      String key = line.substring(0, separator);
      String value = line.substring(separator + 1);
      value.trim();
      root[key] = value;
    }
  }
  f.close();
  clear(FILENAME_JSON);
  File fJson = SPIFFS.open(FILENAME_JSON, "w");
  root.printTo(fJson);
  fJson.close();
  Serial.println("Migrated KeyValueStore to JSON:");
  root.prettyPrintTo(Serial);
  Serial.println();
  clear(FILENAME_OLD);
  return true;
}
开发者ID:cookejames,项目名称:Esp8266KeyValueStore,代码行数:32,代码来源:KeyValueStore.cpp

示例3: saveHTTPAuth

boolean saveHTTPAuth() {
	//flag_config = false;
#ifdef DEBUG
	DBG_OUTPUT_PORT.println("Save secret");
#endif
	StaticJsonBuffer<256> jsonBuffer;
	JsonObject& json = jsonBuffer.createObject();
	json["auth"] = httpAuth.auth;
	json["user"] = httpAuth.wwwUsername;
	json["pass"] = httpAuth.wwwPassword;

	//TODO add AP data to html
	File configFile = SPIFFS.open(SECRET_FILE, "w");
	if (!configFile) {
#ifdef DEBUG
		DBG_OUTPUT_PORT.println("Failed to open secret file for writing");
#endif // DEBUG
		configFile.close();
		return false;
	}

#ifdef DEBUG
	String temp;
	json.prettyPrintTo(temp);
	Serial.println(temp);
#endif

	json.printTo(configFile);
	configFile.flush();
	configFile.close();
	return true;
}
开发者ID:TopperBB,项目名称:FSBrowser,代码行数:32,代码来源:Config.cpp

示例4: handleGetStatus

/**
 * Status JSON api
 */
void handleGetStatus(AsyncWebServerRequest *request)
{
  DEBUG_MSG(SERVER, "%s (%d args)\n", request->url().c_str(), request->params());

  StaticJsonBuffer<512> jsonBuffer;
  JsonObject& json = jsonBuffer.createObject();

  if (request->hasParam("initial")) {
    char buf[8];
    sprintf(buf, "%06x", ESP.getChipId());
    json[F("serial")] = buf;
    json[F("build")] = BUILD;
    json[F("ssid")] = g_ssid;
    // json[F("pass")] = g_pass;
    json[F("middleware")] = g_middleware;
    json[F("flash")] = ESP.getFlashChipRealSize();
    json[F("wifimode")] = (WiFi.getMode() & WIFI_STA) ? "Connected" : "Access Point";
    json[F("ip")] = getIP();
  }

  long heap = ESP.getFreeHeap();
  json[F("uptime")] = millis();
  json[F("heap")] = heap;
  json[F("minheap")] = g_minFreeHeap;
  json[F("resetcode")] = g_resetInfo->reason;
  // json[F("gpio")] = (uint32_t)(((GPI | GPO) & 0xFFFF) | ((GP16I & 0x01) << 16));

  // reset free heap
  g_minFreeHeap = heap;

  jsonResponse(request, 200, json);
}
开发者ID:andig,项目名称:vzero,代码行数:35,代码来源:webserver.cpp

示例5: sensorNotifier

void Mirobot::sensorNotifier(){
  StaticJsonBuffer<60> outBuffer;
  JsonObject& outMsg = outBuffer.createObject();
  if(collideNotify){
    collideState_t currentCollideState = collideState();
    if(currentCollideState != lastCollideState){
      lastCollideState = currentCollideState;
      switch(currentCollideState){
        case BOTH:
          outMsg["msg"] = "both";
          marcel.notify("collide", outMsg);
          break;
        case LEFT:
          outMsg["msg"] = "left";
          marcel.notify("collide", outMsg);
          break;
        case RIGHT:
          outMsg["msg"] = "right";
          marcel.notify("collide", outMsg);
          break;
      }
    }
  }
  if(followNotify){
    readSensors();
    int currentFollowState = leftLineSensor - rightLineSensor;
    if(currentFollowState != lastFollowState){
      outMsg["msg"] = currentFollowState;
      marcel.notify("follow", outMsg);
    }
    lastFollowState = currentFollowState;
  }
}
开发者ID:mirobot,项目名称:mirobot-arduino,代码行数:33,代码来源:Mirobot.cpp

示例6: sendUpdate

void sendUpdate(){
	StaticJsonBuffer<300> sendJsonBuffer;
    JsonObject &json = sendJsonBuffer.createObject();
    json["type"] = "state";
    json["count"] = totalActiveSockets;
	json["time"] = SystemClock.now().toUnixTime();;
	json["mute"] = mute;
	json["source"] = source;
	json["mixing"] = mixing;
	json["enhance"] = enhance;
	json["volumeFR"] = 74-volumeFR;
	json["volumeFL"] = 74-volumeFL;	
	json["volumeRR"] = 74-volumeRR;
	json["volumeRL"] = 74-volumeRL;
	json["volumeCEN"] = 74-volumeCEN;
	json["volumeSW"] = 74-volumeSW;
	json["frequency"] = frequency;
	json["volumeALLCH"] = 74-volumeALLCH;
	json["power"] = power;


	String jsonString;
	json.printTo(jsonString);

	WebSocketsList &clients = server.getActiveWebSockets();
	for (int i = 0; i < clients.count(); i++){
		clients[i].sendString(jsonString);
	}

}
开发者ID:avtehnik,项目名称:esp8266-music-box,代码行数:30,代码来源:application.cpp

示例7: Sensing

void Sensor::Sensing(SensingInfo* info) {
	uint32_t currentTime = millis();
	if ( (currentTime - lastTime) > 2000 ) {
		
		if (count >= MAX_COUNT) {
			StaticJsonBuffer<SENSORDATA_JSON_SIZE>* jsonBuffer = new StaticJsonBuffer<SENSORDATA_JSON_SIZE>; 
			JsonObject& root = jsonBuffer->createObject();
			
			root[FPSTR(TEMPERATURE_KEY)] = prevTemp = nomalization(temperature);
			root[FPSTR(HUMIDITY_KEY)] = prevHumid = nomalization(humidity);
			
			String SensingData = "";
			
			root.printTo(SensingData);
			info->deserialize(SensingData);

			delete jsonBuffer;
			
			requireUpdate = true;
			count = 0;
		}

		checkHumData(count);
		checkTemData(count);
		count++;

		lastTime = currentTime;
	}
}
开发者ID:MyHappyHog,项目名称:ProjectPrototype,代码行数:29,代码来源:Sensor.cpp

示例8: sendData

void HoofSerial::sendData(const DataPacket& dataPacket)
{
  String output;
  const int BUFFER_SIZE = JSON_OBJECT_SIZE(1) + (JSON_ARRAY_SIZE(DATA_ARRAY_SIZE) * (JSON_OBJECT_SIZE(1) + JSON_ARRAY_SIZE(4)));
  
  StaticJsonBuffer<BUFFER_SIZE> jsonBuffer;
  JsonObject& root = jsonBuffer.createObject();       //Build object tree in memory
  
  root["type"] = dataPacket.type;
  JsonArray& dataObj = root.createNestedArray("sample");

  for(unsigned int i = 0; i < DATA_ARRAY_SIZE; i++)
  {
    JsonObject& test = dataObj.createNestedObject();
    test["t"] = dataPacket.data[i].timeStamp; 
     
    JsonArray& obj = test.createNestedArray("f");   

    for(unsigned int j = 0; j < 4; j++)
    {
      obj.add(dataPacket.data[i].data[j]);
    }    
  }
  
  root.printTo(output);       //Generate the JSON string  
  
  this->println(output, true);      //Send over the Serial medium
}
开发者ID:Lirben,项目名称:hoofsoft,代码行数:28,代码来源:HoofSerial.cpp

示例9: loop

boolean Sound::loop() {
  long now = millis();

  if(now - lastReading < 250) {
    return false;
  }

  int reading = analogRead(A0);
  array.push_back(reading);

  lastReading = now;

  if(now - lastPublish < 10000) {
    return false;
  }

  int size = array.size();
  int total = 0;
  double average = 0.0;
  for(int i = 0; i < size; i++)
  {
    total += array[i];
  }

  average = (total / size);

  StaticJsonBuffer<1024> jsonBuffer;
  JsonObject& root = jsonBuffer.createObject();
  root["value"] = average;
  publish(root);

  array.clear();
  lastPublish = now;
}
开发者ID:reauv,项目名称:minor-web-of-things-device,代码行数:34,代码来源:Sound.cpp

示例10: getSettings

void getSettings() {
  StaticJsonBuffer<BUFFER_LENGTH + 1> jsonBuffer;
  JsonObject &json = jsonBuffer.createObject();
  json["threshold"] = threshold;
  json["hysteresis"] = hysteresis;
  sendResponse(200, json);
}
开发者ID:grappendorf,项目名称:signal-tower,代码行数:7,代码来源:main.cpp

示例11: saveSettings

void IoesptPersistance::saveSettings(SaveCallbackType callback)
{
	EEPROM.begin(BufferLen + 2);
	
	StaticJsonBuffer<2000> jsonBuffer;

	JsonObject& root = jsonBuffer.createObject();
	
	callback(root);

	int bufferLength = root.printTo(buffer, length);

	DEBUG_WMS("Saving Eprom contents length:");
	DEBUG_WMF(length);
	
#ifdef IOESPTPERSISTENCE_VERBOSE_OUT
	root.prettyPrintTo(Serial);
#endif // IOESPTPERSISTENCE_VERBOSE_OUT
	DEBUG_WMF("");

	EEPROM.write(0, highByte(bufferLength));
	EEPROM.write(1, lowByte(bufferLength));
	for (int address = 2; address < bufferLength + 2; address++) {
		EEPROM.write(address, buffer[address - 2]);
	}
	EEPROM.commit();
}
开发者ID:mikehole,项目名称:ioespt-libraries,代码行数:27,代码来源:IoesptPersistence.cpp

示例12: store

int16_t CfgDrv::store(const char* fname) {
  if (!fs_ok) return 0;
  uint32_t ms1=millis();
  dirty=false; // to avoid multiple writes...
  File f = SPIFFS.open(fname, "w");
  if (!f) {
    Serial.println(F("Failed to open config file (w)"));
    return 0;
  }
  for(int i=0; i<NCFGS; i++) {
    StaticJsonBuffer<200> jsonBuffer;
    JsonObject& json = jsonBuffer.createObject();
    Serial.print(F("Writing ")); Serial.println(CFG_NAMES[i]);
    json["C"]=CFG_NAMES[i];
    switch(i) {
      case CFG_DBG: json["ON"]=debug_on; break;
      case CFG_SYSL: {
        String addr = log_addr.toString();
        json["ON"]=log_on;
        json["PORT"]=log_port;
        json["ADDR"]=addr;
        break;
      }
      //case CFG_TODO: json["ON"]=3; break;  
      default:;    
    }
    json.printTo(f);
    f.write('\n');
    yield();
  }
  f.close();
  uint16_t t=millis()-ms1;
  Serial.print(F("Cfg written in ")); Serial.println(t);
  return 1;
}
开发者ID:cpana,项目名称:MPU6050,代码行数:35,代码来源:cfg.cpp

示例13: handleRequest

IOperatingMode* BasicMode::handleRequest(WebRequest* webHandler, String request)
{
    int argc = -1;
    String* split = webHandler->splitRequest(request, &argc);

    if(checkParam(split, 0, BASIC))
    {
        if(checkParam(split, 1, TEST))
        {
            webHandler->completeResponse("Hello there");
            return NULL;
        }
        else if(checkParam(split, 1, SET) && checkParam(split, 2, MODE))
        {
            if(checkParam(split, 3, GPIO))
            {
                webHandler->sendResponse(webHandler->createJSONResponse("SET_MODE", "GPIO_MODE", "OK", ""));

                StaticJsonBuffer<200> jsonBuffer;
                JsonObject& root = jsonBuffer.createObject();
                //TODO get JSON from request
                root["gpio"] = 2;

                LEDMode* newmode = new LEDMode();
                newmode->init(this->owner, root);
                return newmode;
            }
            else if(checkParam(split, 3, COMPOSITE))
            {
                webHandler->sendResponse(webHandler->createJSONResponse("SET_MODE", "COMPOSITE_MODE", "OK", ""));

                StaticJsonBuffer<0> jsonBuffer;
                JsonObject& root = jsonBuffer.createObject();
                //TODO create empty JSON in a simpler way

                CompositeMode* newmode = new CompositeMode();
                //Need to create a new one, because the old one will be deleted automatically
                newmode->addMode(new BasicMode());

                newmode->init(this->owner, root);
                return newmode;
            }
        }
    }

    return NULL;
}
开发者ID:LuigiPower,项目名称:esp8266-web-handler,代码行数:47,代码来源:BasicMode.cpp

示例14: save_config

boolean save_config() {
	//flag_config = false;
#ifdef DEBUG
	Serial.println("Save config");
#endif
	StaticJsonBuffer<660> jsonBuffer;
	JsonObject& json = jsonBuffer.createObject();
	json["ssid"] = config.ssid;
	json["pass"] = config.password;
	
	JsonArray& jsonip = json.createNestedArray("ip");
	jsonip.add(config.IP[0]);
	jsonip.add(config.IP[1]);
	jsonip.add(config.IP[2]);
	jsonip.add(config.IP[3]);
	
	JsonArray& jsonNM = json.createNestedArray("netmask");
	jsonNM.add(config.Netmask[0]);
	jsonNM.add(config.Netmask[1]);
	jsonNM.add(config.Netmask[2]);
	jsonNM.add(config.Netmask[3]);
	
	JsonArray& jsonGateway = json.createNestedArray("gateway");
	jsonGateway.add(config.Gateway[0]);
	jsonGateway.add(config.Gateway[1]);
	jsonGateway.add(config.Gateway[2]);
	jsonGateway.add(config.Gateway[3]);
	
	JsonArray& jsondns = json.createNestedArray("dns");
	jsondns.add(config.DNS[0]);
	jsondns.add(config.DNS[1]);
	jsondns.add(config.DNS[2]);
	jsondns.add(config.DNS[3]);
	
	json["dhcp"] = config.dhcp;
	json["ntp"] = config.ntpServerName;
	json["NTPperiod"] = config.Update_Time_Via_NTP_Every;
	json["timeZone"] = config.timezone;
	json["daylight"] = config.daylight;
	json["deviceName"] = config.DeviceName;
			
	//TODO add AP data to html
	File configFile = SPIFFS.open("/config.json", "w");
	if (!configFile) {
		Serial.println("Failed to open config file for writing");
		return false;
	}

#ifdef DEBUG
	String temp;
	json.prettyPrintTo(temp);
	Serial.println(temp);
#endif

	json.printTo(configFile);
	configFile.flush();
	configFile.close();
	return true;
}
开发者ID:darkjavi,项目名称:FSBrowser,代码行数:59,代码来源:Config.cpp

示例15:

TEST(StaticJsonBuffer_Object_Tests, ObjectDoesntGrowWhenFull) {
  StaticJsonBuffer<JSON_OBJECT_SIZE(1)> json;

  JsonObject &obj = json.createObject();
  obj["hello"];
  obj["world"];

  ASSERT_EQ(JSON_OBJECT_SIZE(1), json.size());
}
开发者ID:DgFutureLab,项目名称:satoyama-libs,代码行数:9,代码来源:StaticJsonBuffer_Object_Tests.cpp


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