Announcement

Collapse
No announcement yet.

How PHPoC System Works

Collapse
X
Collapse
  •  

  • How PHPoC System Works

    This post are going to answer to the following questions:
    • How PHPoC system run PHPoC files
    • Which file is mandatory in PHPoC system?
    • Which PHP file is run locally in PHPoC system loop
    • Which PHP files is run in response to HTTP request from outside?
    • How to force a PHP file to run in system loop?
    • How to make PHP file not run in response to HTTP request

    To create IoT devices with PHPoC, we write PHPoC script files and upload them to PHPoC devices. We can upload many files to PHPoC.


    How PHPoC system run PHPoC files?

    There are two ways PHPoC system run PHPoC script file.
    • Run in infinite system loop
    • Run in response to HTTP request

    PHPoC files that are run in infinite system loop

    Like other embedded systems, there is code that run on infinite loop to do some specific tasks. This kind of PHPoC files contain codes that run in infinite loop to do some of the following tasks:
    • Reading value from sensors
    • Controlling actuators
    • Sending/receiving data through Internet via various network protocols

    PHPoC files that are only run in response to HTTP request

    This kind of file is web app files. Apart from PHPoC script, it may contains HTML, JavaScript and CSS code.
    It is only run when there is an HTTP request.

    If I create my_file.php files and upload it to PHPoC, how can I make it run in system loop or in response to HTTP request?

    When you upload my_file.php to PHPoC:
    • It can run when there is an HTTP request without doing anything. You can test it by typing: http://replace_phpoc_ip_addess/my_file.php on web browser to run this file.
    • To make it run in system loop, you need to create init.php file with the following code to tell system that you want to run my_file.php in system loop:
      PHP Code:
      <?php // init.php

              
      system("php my_file.php");

              
      ?>

    What is init.php files?

    init.php file is file that run when PHPoC devices is powered up or restarted.
    It is mainly used to register which file is run in system loop.


    Which file is mandatory

    If the application includes code that need to run in system loop, the init.php file is mandatory. This file is run when PHPoC device is powered or reset. It is mainly used to tell PHPoC system run which files in system loop. For example, the following init.php file tell PHPoC system run file blink_led.php in system loop:
    PHP Code:
    <?php

        system
    ("php blink_led.php");

    ?>

    If the application does NOT include code that need to run in system loop, no file is mandatory.

    Which PHPoC file is run internally in PHPoC system loop?

    The files, which is set in init.php file are run in system loop.

    What is task0.php file?

    It's just a frequently used name of PHPoC file run in PHPoC system loop. The name is not mandatory. You can change it to any name, a long as you specify it on init.php file.


    Which PHPoC files is run in response to HTTP request from outside

    Any files uploaded to PHPoC can be run in response to HTTP request. Assume that IP address of PHPoC device is 192.168.0.2, and there is an PHPoC files with name blink_led.php on PHPoC devices. If we open a web browser and type: 192.168.0.2/blink_led.php , blink_led.php file is run in response to request from web browser, regardless it is running on system loop or not. However, if a file is running in system loop and in response to HTTP request at the same time, it may get errors. Therefore, the PHPoC file running in system loop should not serve HTTP request.

    What is index.php file?

    It's just a frequently used name of PHPoC file run in response for HTTP request. If you type URL or IP address of PHPoC on Web browser without name of file, index.php file is run by default.

    For example, you create two files on PHPoC: index.php and any_name.php. Suppose that IP address of PHPoC is 192.168.0.2.
    If you want to access index.php from web browser, you can type:If you want to access any_name.php from web browser, you can type:There is no limitation of number of files on PHPoC. However, there is limitation of total files size on PHPoC (not exceed 512KB). But it is sufficient for embedded application.


    How to make PHPoC file refuse to serve HTTP request

    It is very simple, just add the following code at the beginning of the files:

    PHP Code:
    if(_SERVER("REQUEST_METHOD"))
        exit; 
    // avoid php execution via http request 

    Is it possible that one file run both on system loop and in response to HTTP request?

    This scenario occurs when a file is running on system loop but there is a request from web browser (HTTP request).
    It's possible. However, in practice, It usually cause errors. Therefore, the PHPoC file running in system loop should not serve HTTP request.

    How to make PHPoC file run in system loop

    It just need to create init.php file and using "php" system command to tell system run that file . For example, If you want blink_led.php to run in system loop, you just need to create init.php file with the following code:
    PHP Code:
    <?php

        system
    ("php blink_led.php");

    ?>

    References
    Last edited by support; 02-08-2018, 03:39 PM.
      Posting comments is disabled.

    Categories

    Collapse

    Latest Articles

    Collapse

    • Arduino - RS-485 Expansion Board
      by support
      PES-2607 is an easy-to-use RS422/RS485 Expansion Board for Arduino Uno and Mega, which allows Arduino to exchange data with serial device via RS422 or RS485.
      Especially, Arduino does NOT use UART pins to communicate with RS422/RS485 expansion board. Therefore, users can use Arduino UART pins for other purposes.
      Moreover, A single Arduino Uno/Mega can communicate with multiple RS422/RS485 expansion boards (up to 14) without using Arduino UART pins.

      Library and examples for...
      11-13-2018, 02:45 PM
    • Arduino - RS-422 Expansion Board
      by support
      PES-2607 is an easy-to-use RS422/RS485 Expansion Board for Arduino Uno and Mega, which allows Arduino to exchange data with serial device via RS422 or RS485.
      Especially, Arduino does NOT use UART pins to communicate with RS422/RS485 expansion board. Therefore, users can use Arduino UART pins for other purposes.
      Moreover, A single Arduino Uno/Mega can communicate with multiple RS422/RS485 expansion boards (up to 14) without using Arduino UART pins.

      Library and examples for...
      11-13-2018, 02:44 PM
    • Arduino - RS-232 Expansion Board
      by support
      PES-2606 is an easy-to-use RS-232 Expansion Board for Arduino Uno and Mega, which allows Arduino to exchange data with serial device via RS-232.
      Especially, Arduino does NOT use UART pins to communicate with RS-232 expansion board. Therefore, users can use Arduino UART pins for other purposes.
      Moreover, A single Arduino Uno/Mega can communicate with multiple RS-232 expansion boards (up to 14) without using Arduino UART pins.

      Library and example for the RS-232 expansion board...
      11-13-2018, 02:43 PM
    • Arduino - Stepper Motor Controller
      by support
      PES-2605 is an easy-to-use stepper motor controller for Arduino Uno and Mega, which uses micro-stepping method to precisely control stepper motor.
      Library and example for the stepper motor controller are part of of PhpocExpansion library for Arduino. The library reference is available here.

      This tutorial shows how to use the step motor controller with an example of PhpocExpansion library for Arduino.


      Hardware Required...
      11-13-2018, 02:41 PM
    • Arduino - DC Motor Controller
      by support
      PES-2604 is an easy-to-use DC motor controller for Arduino Uno and Mega.
      Library and example for the DC motor controller are part of of PhpocExpansion library for Arduino. The library reference is available here.

      This tutorial shows how to use the DC motor controller with an example of PhpocExpansion library for Arduino.


      Hardware Required...
      11-13-2018, 02:40 PM
    • Arduino - Digital Input Board
      by support
      PES-2602 is an easy-to-use 4-port Input Expansion Board for Arduino Uno and Mega, which allows Arduino to monitor state of DC electric device. In addition, it can monitor NPN, PNP and dry contact(relay).
      Library and example for the 4-port input expansion board are part of of PhpocExpansion library for Arduino. The library reference is available here.

      This tutorial shows how to use 4-port input expansion board with an example of PhpocExpansion library for Arduino.

      ...
      11-13-2018, 02:39 PM
    Working...
    X