Arduino JSON package - formatting sensor value Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Safely turning a JSON string into an objectHow do I format a Microsoft JSON date?Can comments be used in JSON?How can I pretty-print JSON in a shell script?What is the correct JSON content type?Why does Google prepend while(1); to their JSON responses?How can I pretty-print JSON using JavaScript?Parse JSON in JavaScript?How do I POST JSON data with Curl from a terminal/commandline to Test Spring REST?The “right” JSON date format
Is a copyright notice with a non-existent name be invalid?
Derived column in a data extension
Determine whether an integer is a palindrome
Why did Bronn offer to be Tyrion Lannister's champion in trial by combat?
What is a more techy Technical Writer job title that isn't cutesy or confusing?
In musical terms, what properties are varied by the human voice to produce different words / syllables?
Why does BitLocker not use RSA?
Is the Mordenkainen's Sword spell underpowered?
Flight departed from the gate 5 min before scheduled departure time. Refund options
Short story about astronauts fertilizing soil with their own bodies
Does a random sequence of vectors span a Hilbert space?
Adapting the Chinese Remainder Theorem (CRT) for integers to polynomials
Vertical ranges of Column Plots in 12
Where did Ptolemy compare the Earth to the distance of fixed stars?
Sally's older brother
French equivalents of おしゃれは足元から (Every good outfit starts with the shoes)
malloc in main() or malloc in another function: allocating memory for a struct and its members
What is "Lambda" in Heston's original paper on stochastic volatility models?
How to achieve cat-like agility?
Why complex landing gears are used instead of simple, reliable and light weight muscle wire or shape memory alloys?
Table formatting with tabularx?
One-one communication
Noise in Eigenvalues plot
Does the universe have a fixed centre of mass?
Arduino JSON package - formatting sensor value
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!Safely turning a JSON string into an objectHow do I format a Microsoft JSON date?Can comments be used in JSON?How can I pretty-print JSON in a shell script?What is the correct JSON content type?Why does Google prepend while(1); to their JSON responses?How can I pretty-print JSON using JavaScript?Parse JSON in JavaScript?How do I POST JSON data with Curl from a terminal/commandline to Test Spring REST?The “right” JSON date format
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
#include <ArduinoJson.h>
#include <SimpleDHT.h>
String input = ""temperature":"26";
SimpleDHT11 dht11;
byte temperature = 0;
int err = SimpleDHTErrSuccess;
void loop {
StaticJsonBuffer<512> dataBuffer;
if (err = dht11.read(2, &temperature, NULL)) == simpleDHTErrSuccess)
Serial.print((int) temperature);
JsonObject& dataRoot = dataBuffer.parseObject(input);
*long Temperature = dataRoot[String("temperature")];
*Temperature = (long)temperature;
*dataRoot[String("temperature")] = Temperature;
String output;
dataRoot.printTo(output);
I have here a snippet of Arduino code used to format a DHT11 temperature sensor readings in JSON, to allow for live streaming of the data on a web client. This was obtained from this project I am using for inspiration https://www.twilio.com/blog/2018/07/watch-iot-sensors-esp32-javascript-nodejs-twilio-sync.html.
I am instead attempting to pull data from a Myoware muscle sensor. The amplitude value I am wanting can simply be queried like so:
int sensorValue = analogRead(A0);
I need help in understanding how the parseObject function works and what the purpose of the 'input' string is. All I want is for my sensor's value to be fed to the client side which displays it in a graph. The three lines I have asterisked are particularly confusing.
Thanks!
json arduino twilio
add a comment |
#include <ArduinoJson.h>
#include <SimpleDHT.h>
String input = ""temperature":"26";
SimpleDHT11 dht11;
byte temperature = 0;
int err = SimpleDHTErrSuccess;
void loop {
StaticJsonBuffer<512> dataBuffer;
if (err = dht11.read(2, &temperature, NULL)) == simpleDHTErrSuccess)
Serial.print((int) temperature);
JsonObject& dataRoot = dataBuffer.parseObject(input);
*long Temperature = dataRoot[String("temperature")];
*Temperature = (long)temperature;
*dataRoot[String("temperature")] = Temperature;
String output;
dataRoot.printTo(output);
I have here a snippet of Arduino code used to format a DHT11 temperature sensor readings in JSON, to allow for live streaming of the data on a web client. This was obtained from this project I am using for inspiration https://www.twilio.com/blog/2018/07/watch-iot-sensors-esp32-javascript-nodejs-twilio-sync.html.
I am instead attempting to pull data from a Myoware muscle sensor. The amplitude value I am wanting can simply be queried like so:
int sensorValue = analogRead(A0);
I need help in understanding how the parseObject function works and what the purpose of the 'input' string is. All I want is for my sensor's value to be fed to the client side which displays it in a graph. The three lines I have asterisked are particularly confusing.
Thanks!
json arduino twilio
add a comment |
#include <ArduinoJson.h>
#include <SimpleDHT.h>
String input = ""temperature":"26";
SimpleDHT11 dht11;
byte temperature = 0;
int err = SimpleDHTErrSuccess;
void loop {
StaticJsonBuffer<512> dataBuffer;
if (err = dht11.read(2, &temperature, NULL)) == simpleDHTErrSuccess)
Serial.print((int) temperature);
JsonObject& dataRoot = dataBuffer.parseObject(input);
*long Temperature = dataRoot[String("temperature")];
*Temperature = (long)temperature;
*dataRoot[String("temperature")] = Temperature;
String output;
dataRoot.printTo(output);
I have here a snippet of Arduino code used to format a DHT11 temperature sensor readings in JSON, to allow for live streaming of the data on a web client. This was obtained from this project I am using for inspiration https://www.twilio.com/blog/2018/07/watch-iot-sensors-esp32-javascript-nodejs-twilio-sync.html.
I am instead attempting to pull data from a Myoware muscle sensor. The amplitude value I am wanting can simply be queried like so:
int sensorValue = analogRead(A0);
I need help in understanding how the parseObject function works and what the purpose of the 'input' string is. All I want is for my sensor's value to be fed to the client side which displays it in a graph. The three lines I have asterisked are particularly confusing.
Thanks!
json arduino twilio
#include <ArduinoJson.h>
#include <SimpleDHT.h>
String input = ""temperature":"26";
SimpleDHT11 dht11;
byte temperature = 0;
int err = SimpleDHTErrSuccess;
void loop {
StaticJsonBuffer<512> dataBuffer;
if (err = dht11.read(2, &temperature, NULL)) == simpleDHTErrSuccess)
Serial.print((int) temperature);
JsonObject& dataRoot = dataBuffer.parseObject(input);
*long Temperature = dataRoot[String("temperature")];
*Temperature = (long)temperature;
*dataRoot[String("temperature")] = Temperature;
String output;
dataRoot.printTo(output);
I have here a snippet of Arduino code used to format a DHT11 temperature sensor readings in JSON, to allow for live streaming of the data on a web client. This was obtained from this project I am using for inspiration https://www.twilio.com/blog/2018/07/watch-iot-sensors-esp32-javascript-nodejs-twilio-sync.html.
I am instead attempting to pull data from a Myoware muscle sensor. The amplitude value I am wanting can simply be queried like so:
int sensorValue = analogRead(A0);
I need help in understanding how the parseObject function works and what the purpose of the 'input' string is. All I want is for my sensor's value to be fed to the client side which displays it in a graph. The three lines I have asterisked are particularly confusing.
Thanks!
json arduino twilio
json arduino twilio
asked Mar 22 at 12:47
user1893110user1893110
9217
9217
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
The method parseObject()
allocates and populate a JsonObject (that you can work with) from a JSON string.
The "JsonObject" in your code example is named dataRoot
and is defined with
JsonObject& dataRoot = dataBuffer.parseObject(input);
where dataBuffer
comes from StaticJsonBuffer<512> dataBuffer;
which is the entry point for using the ArduinoJson
library, and
where input
has the value of the JSON string ""temperature":"26""
which follows the standard JSON attribute-value pair format (you need a JSON string to work with and then send it to the client side).
After JsonObject& dataRoot = dataBuffer.parseObject(input);
is executed, you get dataRoot
as an object with a property named temperature
and you can access this property with dataRoot[String("temperature")]
So the three lines:
long Temperature = dataRoot[String("temperature")];
Temperature = (long)temperature;
dataRoot[String("temperature")] = Temperature;
are used to update the value of the temperature
attribute with whatever is read from the sensor.
A bit confusing in the example code is the fact that the name of the JSON attribute is temperature
and also the name for the variable to hold the temperature read from sensor is also temperature
. They are different things.
Thank you truly for your thoughtful, comprehensive answer!
– user1893110
Mar 25 at 13:51
You're welcome, glad it helped. Arduinos are fun.
– Alex Baban
Mar 25 at 15:08
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55299956%2farduino-json-package-formatting-sensor-value%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The method parseObject()
allocates and populate a JsonObject (that you can work with) from a JSON string.
The "JsonObject" in your code example is named dataRoot
and is defined with
JsonObject& dataRoot = dataBuffer.parseObject(input);
where dataBuffer
comes from StaticJsonBuffer<512> dataBuffer;
which is the entry point for using the ArduinoJson
library, and
where input
has the value of the JSON string ""temperature":"26""
which follows the standard JSON attribute-value pair format (you need a JSON string to work with and then send it to the client side).
After JsonObject& dataRoot = dataBuffer.parseObject(input);
is executed, you get dataRoot
as an object with a property named temperature
and you can access this property with dataRoot[String("temperature")]
So the three lines:
long Temperature = dataRoot[String("temperature")];
Temperature = (long)temperature;
dataRoot[String("temperature")] = Temperature;
are used to update the value of the temperature
attribute with whatever is read from the sensor.
A bit confusing in the example code is the fact that the name of the JSON attribute is temperature
and also the name for the variable to hold the temperature read from sensor is also temperature
. They are different things.
Thank you truly for your thoughtful, comprehensive answer!
– user1893110
Mar 25 at 13:51
You're welcome, glad it helped. Arduinos are fun.
– Alex Baban
Mar 25 at 15:08
add a comment |
The method parseObject()
allocates and populate a JsonObject (that you can work with) from a JSON string.
The "JsonObject" in your code example is named dataRoot
and is defined with
JsonObject& dataRoot = dataBuffer.parseObject(input);
where dataBuffer
comes from StaticJsonBuffer<512> dataBuffer;
which is the entry point for using the ArduinoJson
library, and
where input
has the value of the JSON string ""temperature":"26""
which follows the standard JSON attribute-value pair format (you need a JSON string to work with and then send it to the client side).
After JsonObject& dataRoot = dataBuffer.parseObject(input);
is executed, you get dataRoot
as an object with a property named temperature
and you can access this property with dataRoot[String("temperature")]
So the three lines:
long Temperature = dataRoot[String("temperature")];
Temperature = (long)temperature;
dataRoot[String("temperature")] = Temperature;
are used to update the value of the temperature
attribute with whatever is read from the sensor.
A bit confusing in the example code is the fact that the name of the JSON attribute is temperature
and also the name for the variable to hold the temperature read from sensor is also temperature
. They are different things.
Thank you truly for your thoughtful, comprehensive answer!
– user1893110
Mar 25 at 13:51
You're welcome, glad it helped. Arduinos are fun.
– Alex Baban
Mar 25 at 15:08
add a comment |
The method parseObject()
allocates and populate a JsonObject (that you can work with) from a JSON string.
The "JsonObject" in your code example is named dataRoot
and is defined with
JsonObject& dataRoot = dataBuffer.parseObject(input);
where dataBuffer
comes from StaticJsonBuffer<512> dataBuffer;
which is the entry point for using the ArduinoJson
library, and
where input
has the value of the JSON string ""temperature":"26""
which follows the standard JSON attribute-value pair format (you need a JSON string to work with and then send it to the client side).
After JsonObject& dataRoot = dataBuffer.parseObject(input);
is executed, you get dataRoot
as an object with a property named temperature
and you can access this property with dataRoot[String("temperature")]
So the three lines:
long Temperature = dataRoot[String("temperature")];
Temperature = (long)temperature;
dataRoot[String("temperature")] = Temperature;
are used to update the value of the temperature
attribute with whatever is read from the sensor.
A bit confusing in the example code is the fact that the name of the JSON attribute is temperature
and also the name for the variable to hold the temperature read from sensor is also temperature
. They are different things.
The method parseObject()
allocates and populate a JsonObject (that you can work with) from a JSON string.
The "JsonObject" in your code example is named dataRoot
and is defined with
JsonObject& dataRoot = dataBuffer.parseObject(input);
where dataBuffer
comes from StaticJsonBuffer<512> dataBuffer;
which is the entry point for using the ArduinoJson
library, and
where input
has the value of the JSON string ""temperature":"26""
which follows the standard JSON attribute-value pair format (you need a JSON string to work with and then send it to the client side).
After JsonObject& dataRoot = dataBuffer.parseObject(input);
is executed, you get dataRoot
as an object with a property named temperature
and you can access this property with dataRoot[String("temperature")]
So the three lines:
long Temperature = dataRoot[String("temperature")];
Temperature = (long)temperature;
dataRoot[String("temperature")] = Temperature;
are used to update the value of the temperature
attribute with whatever is read from the sensor.
A bit confusing in the example code is the fact that the name of the JSON attribute is temperature
and also the name for the variable to hold the temperature read from sensor is also temperature
. They are different things.
edited Mar 22 at 20:09
answered Mar 22 at 19:20
Alex BabanAlex Baban
6,86031525
6,86031525
Thank you truly for your thoughtful, comprehensive answer!
– user1893110
Mar 25 at 13:51
You're welcome, glad it helped. Arduinos are fun.
– Alex Baban
Mar 25 at 15:08
add a comment |
Thank you truly for your thoughtful, comprehensive answer!
– user1893110
Mar 25 at 13:51
You're welcome, glad it helped. Arduinos are fun.
– Alex Baban
Mar 25 at 15:08
Thank you truly for your thoughtful, comprehensive answer!
– user1893110
Mar 25 at 13:51
Thank you truly for your thoughtful, comprehensive answer!
– user1893110
Mar 25 at 13:51
You're welcome, glad it helped. Arduinos are fun.
– Alex Baban
Mar 25 at 15:08
You're welcome, glad it helped. Arduinos are fun.
– Alex Baban
Mar 25 at 15:08
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55299956%2farduino-json-package-formatting-sensor-value%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown