간단하게 아두이노 Nano 33 IoT 보드에서 확인할 수 있도록 예제를 제공합니다.
Decoding / Parsing 예제 구문은 아래에 있고 IoT보드에 올리려서 테스트하느 코드도 함께 올립니다.
char json[] = "{\"sensor\":\"gps\",\"time\":1351824120,\"data\":[48.756080,2.302038]}";
StaticJsonBuffer<200> jsonBuffer;
JsonObject& root = jsonBuffer.parseObject(json);
const char* sensor = root["sensor"];
long time = root["time"];
double latitude = root["data"][0];
double longitude = root["data"][1];
#include <ArduinoJson.h>
StaticJsonBuffer<200> jsonBuffer;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
StaticJsonBuffer<200> jsonBuffer;
JsonObject& object = jsonBuffer.createObject();
object["hello"] = "world";
object.printTo(Serial);
delay(5000);
}
Encoding / Generating 예제 구문은 아래에 있고 IoT보드에 올리려서 테스트하느 코드도 함께 올립니다.
StaticJsonBuffer<200> jsonBuffer;
JsonObject& root = jsonBuffer.createObject();
root["sensor"] = "gps";
root["time"] = 1351824120;
JsonArray& data = root.createNestedArray("data");
data.add(48.756080, 6); // 6 is the number of decimals to print
data.add(2.302038, 6); // if not specified, 2 digits are printed
root.printTo(Serial);
// This prints:
// {"sensor":"gps","time":1351824120,"data":[48.756080,2.302038]}
#include <ArduinoJson.h>
StaticJsonBuffer<200> jsonBuffer;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
JsonObject& root = jsonBuffer.createObject();
root["sensor"] = "gps";
root["time"] = 1351824120;
JsonArray& data = root.createNestedArray("data");
data.add(48.756080, 6); // 6 is the number of decimals to print
data.add(2.302038, 6); // if not specified, 2 digits are printed
root.printTo(Serial);
Serial.println("");
delay(5000);
}

'개발자 > Arduino' 카테고리의 다른 글
| openweathermap 온도 데이터를 섭씨온도로 변환 (0) | 2020.10.13 |
|---|---|
| Decoding and Encoding JSON with Arduino Nano 33 IoT 3 (0) | 2020.10.12 |
| Decoding and Encoding JSON with Arduino Nano 33 IoT 1 (0) | 2020.10.10 |
| Decoding and Encoding JSON with Arduino Nano 33 IoT 2 (0) | 2020.10.09 |
| format을 가진 출력을 위한 sprintf( ), dtostrf( ) (0) | 2020.10.07 |
| SSD1306 OLED 로 LM35 온도센서 값을 디스플레이 (0) | 2020.10.07 |
| 달리기와 술자리도 마다하고, 여기까지 돌아가는 코드 (0) | 2020.10.06 |
| Nano 33 IoT 보드 온도 습도 센서 dht11 테스트 (0) | 2020.10.06 |
취업, 창업의 막막함, 외주 관리, 제품 부재!
당신의 고민은 무엇입니까? 현실과 동떨어진 교육, 실패만 반복하는 외주 계약,
아이디어는 있지만 구현할 기술이 없는 막막함.
우리는 알고 있습니다. 문제의 원인은 '명확한 학습, 실전 경험과 신뢰할 수 있는 기술력의 부재'에서 시작됩니다.
이제 고민을 멈추고, 캐어랩을 만나세요!
코딩(펌웨어), 전자부품과 디지털 회로설계, PCB 설계 제작, 고객(시장/수출) 발굴과 마케팅 전략으로 당신을 지원합니다.
제품 설계의 고수는 성공이 만든 게 아니라 실패가 만듭니다. 아이디어를 양산 가능한 제품으로!
귀사의 제품을 만드세요. 교육과 개발 실적으로 신뢰할 수 있는 파트너를 확보하세요.
지난 30년 여정, 캐어랩이 얻은 모든 것을 함께 나누고 싶습니다.
귀사가 성공하기까지의 긴 고난의 시간을 캐어랩과 함께 하세요.
캐어랩