I have and ESP32 and ESP8266 sending data via mqqt to Mosquito running on a RasperryPi. On the PI I have a web page and javaScript code displaying the mqqt data.
On the server side I want to save some setting for the webpage, IP, port, etc in a simple .json file or text file. I have been searching the web for a example but can’t seem to find what I am looking for. I am not sure if I need to switch to PHP, or can do something simple in JavaScript or some other way.
Can someone point me in the right direction?
Thank, Glen
Hello Glenn, You can handle JSON files with PHP or Javascript both options will accomplish the same task.
Which one are you already most familiar with?
Regards.
Sara
That would be JavaScript. In reading about both, seems like PHP is what I want. What I’ve read so far is that JavaScript would save a file on the local computer, not the server which is the direction I think I am looking for.
The overall process I am trying to obtain is not “hard coding” items in the JavaScript of my webserver code.
Glen
If you are more comfortable with Javascript and don’t want to learn PHP there is server side javascript called Node.js. You can save a file with JSON or integrate MySQL database with Node.js easily.
@Glen Brackett, as @Steve Mercer suggested you have two options:
- PHP (server side)
- Node.js – JavaScript (server side)
You can convert variables or format them in JSON format using PHP:
Then, you can using the PHP file_put_contents() Function to create a JSON file:
I don’t have any guides on that exact topic, but if you get started by encoding/decoding variable into JSON, then store/read them from a JSON file, you should be able to do it.