An example sketch I found online to post an HTTP request using arduino contains the following code
String payload_pattern = "{'id':'MyESP','sensors':[{'id': 'Temperature','data': $temperature$},
{'id':'Humidity','value': $humidity$},{'id': 'Counter','value': $counter$}]}";
Further down in the sketch
counter += 1;
float temperature = 23.456;
float humidity = 80.21;
String payload = payload_pattern;
payload.replace("$temperature$",String(temperature));
payload.replace("$humidity$",String(humidity));
payload.replace("$counter$",String(counter));
What I don't understand is the $variable$
syntax. I assume it will substitute the actual value of the variables later but I haven't seen such syntax before. Initially I thought its a way of referencing just like using the ampersand operator but not sure. Also I couldn't find much info on the web. Could you please explain what that syntax is and what is it called?
payload.replace("$counter$",String(counter));
– jsotola May 24 '20 at 1:04