Tell me how you can do it in php so that each time you run the script select another parameter?

There is such a line: http://192.168.0.15/?R7_off; it switches the relay to one position on the arduinka, but this one into another http://192.168.0.15/?R7_on

It is necessary that when I run a php script every time _on changed to _off

  • Few details. How do you run php? Web server or CLI? Does this link handle php code or arduin itself? - korytoff
  • Web server. Through the button in the WEB, I press and work out any php script that I put into it. On Arduin only web server which understands the two states _off and _on. - Kirill Kulakov
  • ghost example php code and buttons - korytoff
  • It will be difficult to make this a whole system and it is not clear how and from where to get it. This is the majordom system. The button will work any php which we shove. All you need is a code that will write (somewhere to a variable, to a file) the level of the last launch and launch and send another link. For example: if the previous script launch was a request to the address from _on Then we make a request by reference to _off, add an entry to the file or variable about the last transition from the _off link - Cyril Kulakov

3 answers 3

If I understood correctly, then you want to make a toggler, the easiest option, save the past state to a file and invert it the next time, use the second option, use a cache, for example http://php.net/manual/ru/book.apc .php

  • "This extension is considered unsupported and dead" © Help - teran
  • I just haven’t been out for a long time, but I think I’ve told you the essence, you have to keep the state, you have a lot of options - Vyacheslav Gusser
  • you can still request it if one is supported. It would be safer. - teran
  • Well, yes, one could request the current state from the Arduino itself - Vyacheslav Gusser
  • Thanks for the tip. I study. I myself do not know the same php. - Kirill Fists

If I understand correctly, these addresses in question are processed by php and there is a button on the page, then why not just change the URL of the button (link) on the page depending on the get parameter?

 <a href="http://192.168.0.15/?R7_<?= isset(_GET['R7_off']) ? 'on' : 'off' ?>">Переключатель</a> 
  • This is the majordom system and the change button is not an option, you just need a code in a php script. Any php smart script button will work. There, the buttons in the system are sewn up and they do nothing except the working out of the script. - Kirill Kulakov

In my view, the code should be something like this, but I don’t know how to describe this in php.

  if (laststat = '_on') to file_get_contents('http://192.168.0.15/?R7_' + '_on'); else file_get_contents('http://192.168.0.15/?R7_' + '_off'); //Записываем в переменную последний запуск set = '_off' 
  • Although it may be easier to do the same for arduino. - Kirill Fists