0

I have a couple of sensors communicating with my javascript, that runs on my server on a Raspberry Pi, whenever it senses a motion.

What I want to do is to write/edit an XML file whenever the status changes so that I can read the .xml file from an android app.

After searching the web for a couple of days this seems to be a troubling thing to do for me.

My first approach was to just write to the file using javascript, but this is apparently almost impossible.

My second approach was to use PHP inside my javascript, which also seems like a hard thing to accomplish.

I am pretty new to both javascript and PHP. Could anyone help me out with this problem, or at least point me in the right direction?

Code:

if (data == "3:SSR:0")
{
      $('#ROM1 .btn-text').text('ROM1 (Ledig)').parent().css("background", "green");
      lights["ROM1"] = "Ledig";
}

I want to write to the file whenever if (data == "3:SSR:0") is true.

7
  • PHP runs on a server, Javascript normally runs in the browser on a client which has no access to the file system on a computer for security reasons so you will need to. Is this a process running on a server or in a client? Commented Mar 26, 2015 at 13:00
  • Pretty certain it runs on the server. The thing is, i am making an android app, but I need to pull the sensor status from somewhere, and tought writing to xml and then reading it from the app would be a good approach. Not so sure now.. Commented Mar 26, 2015 at 13:04
  • The solution would be to use Ajax. Basicly you'll send whatever data you wish to save in XML format towards a php file that in turn will write the XML file for you. Commented Mar 26, 2015 at 13:06
  • Is all this happening on the phone/android device itself or are you sending information from the phone up to a server on the internet somewhere and then reading it back down from the server to the phone? Commented Mar 26, 2015 at 13:09
  • 1
    You may want to update your question with information about where things are happening. It sounds like you have a phone and a server involved but it's not clear where you are getting sensor data from, and where you are using it. Commented Mar 26, 2015 at 13:21

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.