uPHP functions have an identical syntax to PHP functions in most cases. Below is a list of all the functions that have been implemented.
Certain additional functions are available as WattmonOS include files. For a list of these see library_functions.
Click on the function name for further details:
| FUNCTION NAME | PARAMETER(S) | RETURN | DESCRIPTION |
|---|---|---|---|
| adc_read | int channel | int ADC value | Read an onboard ADC channel |
| aes_decrypt | string text, int length, string key, string iv | string with data | Return an AES-decrypted string |
| aes_encrypt | string text, int length, string key,string iv | string with data | Return an AES-encrypted string |
| array | mixed values ... | array | Create an array, with optional values |
| array_key | array, int index | string key | Return the key for an array index |
| array_keys | array with key/value pairs | array of keys | Return keys for an array that has key/value pairs |
| array_resize | array indexed array, int length | none | Resize indexed array |
| base64_decode | string base64 | string decoded or int 0 | Decode a base64-encoded string |
| base64_encode | string to encode | string base64 or int 0 | Return the base64-encoded version of a string |
| call_user_func | string function_name, mixed parameters ... | mixed result | Call a user defined function with optional parameters |
| charat | string, int index | int ASCII code | Return the ASCII code for a character in a string at an index |
| chdir | string directory | int 0=OK | Change the current directory |
| chr | int code | string 1 character | Return the character for an ASCII code |
| clear_watchdog | Clear the software watchdog timer | ||
| cos | number radian_angle | float cosine | Return cosine of a radian_angle |
| debug | string output | Print to debug output | |
| debugout | int 0 or 1 | Enable or disable debug messages | |
| die | Kill the script | ||
| disk_free_space | int drive | int KiloBytes | Return free space on drive |
| disk_status | int drive | int Status | Return mount status of drive |
| disk_total_space | int drive | int KiloBytes | Return total space on drive |
| disk_type | int drive | int type | Return disk type |
| download | string url | int res | Download a file in the background |
| download_info | array info | Get info about ongoing download | |
| download_state | int status | Get state of download | |
| error_reporting | int verbosity | Set the debug output level | |
| ereg | string pattern, string content [, &array matches] | int | Perform a regex operation |
| exec | string script, int delay | Run a script with an optional delay | |
| exec_action | mixed action | int 1=OK | Triggers a manually executable action by id or name |
| explode | string, string delimiter | array | Turn a string into an array |
| f485open | int baud, int parity | int handle or 0 | Open the RS-485 port at the specified baud rate and parity |
| fclose | int handle | Close a file, stream or socket | |
| feof | int handle | int 1 or 0 | Test if no more data is available in a file, stream or socket |
| fgets | int handle, int size | string or int -1 | Return a single line from a file, stream or socket, with optional size limit |
| file_exists | string filename | int 1 or 0 | Check if a file exists |
| filemtime | string filename | int bytes | Return the last modified timestamp for a file |
| filesize | string filename or int handle | int bytes | Return the size of a file, or the number of unread bytes in a stream or socket |
| findfirst | string pattern, int attributes | array first file found | Start searching the current folder for files matching a pattern and attributes |
| findnext | array next file found | Return next matching file information (after a findfirst) | |
| firmwareupdate | Initiate a firmware update sequence and reboot the device | ||
| flash_status | array status | int get_full | Return an array of flash status information |
| floatval | mixed value | float value or int 0/1 | Return the float value of a number or string |
| flush | socket socket to flush | Flush current output or socket to the browser | |
| fopen | string filename, string mode | int handle or 0 | Open a file for reading or writing |
| fread | int handle, int bytes | string or int 0 | Read bytes from a file, stream or socket |
| fread_unpack | int handle,string format, int count, int interval | number | Write contents of an indexed array to a file in binary |
| freemem | int bytes | Return free memory space | |
| freestack | int bytes | Return free stack space | |
| fseek | int handle, int offset, int whence | Position the file pointer in an open file | |
| fseropen | int baud, int blocking, int invert, int parity | int handle or 0 | Open the serial port at the specified baud rate with optional parameters |
| fsockopen | string host, int port, int timeout | int handle or 0 | Open an internet socket connection with optional timeout |
| ftell | int handle | int position | Return the current position of a file read/write pointer |
| ftp_command | string result | string command] | Send an FTP command |
| ftp_close | int result | Close an active connection with FTP server | |
| ftp_download | int result | string remote_file,string local_file,[int position] | Initiate a download of a remote file |
| ftp_error | int result | Get last FTP response code | |
| ftp_is_busy | int result | Check if the FTP engine is busy | |
| ftp_is_connected | int result | Check if the FTP connection is active | |
| ftp_is_connecting | int result | Check if the FTP connection is in the process of connecting | |
| ftp_list | int result | string folder, string output_file | Lists a folder on the FTP server and outputs the result to the specified file |
| ftp_open | int result | string host, int port, string username, string password, int keepalive, int ignore_reply | Open a connection to an FTP server |
| ftp_size | int size | string filename | Get the file size of a file on the FTP server |
| ftp_status | array status | ||
| ftp_upload | int result | string remote_file,string local_file,[int position] | Initiate an upload of a file |
| function_exists | string function_name | int 1 or 0 | Check if a function exists (custom or native) |
| fwrite | int handle, mixed data, int length | int bytes written or -1 | Write data to a file, stream or socket |
| fwrite_pack | int handle,array data, int length | number | Write contents of an indexed array to a file in binary |
| get_csv_data | string filename,string columns, int interval, int json | string | Extract partial CSV data from a CSV file |
| get3gstat | array | Get cellular data connection status information | |
| getcwd | string path | Get the current directory | |
| getethstat | array | Get Ethernet connection status information | |
| getmac | string MAC | Get the Wattmon's MAC address | |
| gettype | any variable | string type | Get a variable type as a string |
| getusbstat | array | Get USB host status information | |
| getwifistat | array | Get WIFI status information | |
| header | string header_data | Add to HTTP header | |
| hash_hmac | string algorithm, string data, string key | string converted | Generate a keyed hash value using the HMAC method |
| htmlspecialchars | string data | string converted | Convert special characters for display in HTML |
| ieee754toint | float value | int representation | Convert a float value to an IEEE-754 encoded integer (32 bit) |
| implode | array, string delimiter | string | Turn an array into a string |
| include | string filename | Include a file within the current script at the current location | |
| indexed_array | int type, int size | array | Create an array of a specific type and size |
| ini_get | string filename, string section, string key, mixed default | mixed value | Get a value from an INI file |
| ini_get_array | string filename, string section | array | Get a group of parameters from an INI file as an array |
| ini_put_array | string filename, array data, string section | Write a group of parameters to an INI file from an array | |
| ini_set | string filename, string section, string key, mixed value | int 1=OK | Set a value in an INI file |
| init_watchdog | int interval | Initialize the software watchdog timer | |
| inttoieee754 | int representation | float value | Convert an IEEE-754 encoded integer representation (32 bit) to a float |
| intval | mixed value | int value | Return the integer value of a number or string |
| is_array | mixed variable | int 1 or 0 | Check if a variable is an array |
| is_float | mixed variable | int 1 or 0 | Check if a variable is a float |
| is_int | mixed variable | int 1 or 0 | Check if a variable is an integer |
| is_numeric | mixed value | int 1 or 0 | Check if a value is numeric (int, float or numeric string) |
| is_string | mixed variable | int 1 or 0 | Check if a variable is a string |
| isset | mixed variable | int 1 or 0 | Check if a variable exists |
| json_decode | string | array | JSON decode a string into an array |
| json_encode | array, int method | string | JSON encode an array into a string, with optional method |
| ln | number number | float loge | Return the natural logarithm of a number |
| log | string output, string file | Print to the System Log (or optional file) | |
| log10 | number number | float log10 | Return the base 10 logarithm of a number |
| string recipient, string subject, string body | int 0 or SMTP error code | Send an email [deprecated] | |
| max_execution_time | int seconds | Set the maximum execution time for the current script | |
| mb_add_dev | int id, int type, string name, int poll_interval, int status, int bus | int 0=OK | Add a device to the list of polled devices |
| mb_delete_dev | int id | int 1=OK | Delete a device from the list of active devices |
| mb_get_dev_by_id | int id | array | Return modbus device details by id |
| mb_get_dev_by_index | int index | array | Return modbus device details by index |
| mb_get_dev_by_name | string name | array | Return modbus device details by name |
| mb_get_dev_info | int type | array | Return modbus device details by type |
| mb_get_role_array | array | Return an array of all roles and their values | |
| mb_get_status_by_role | int role | int 1=OK | Return status of the device attached to the role |
| mb_get_val_by_role | int role | number | Return value of the role |
| mb_num_devices | int | Return number of devices on the modbus | |
| mb_queue_command | mixed values ... | array of numbers | Queue a sequence of characters to the RS-485 bus and get but ignore the reply |
| mb_scan_complete | int 1=complete, 0=ongoing | Check to see if a modbus scan has completed | |
| mb_scan_percent | number percent completed | Return scan percentage completed | |
| mb_send_command | mixed values ... | array of numbers | Send a sequence of characters to the RS-485 bus and get a reply |
| mb_set_dev_var | string name or int id, string variable, mixed value | int 1=OK | Set a variable on a modbus device |
| mb_set_val_by_role | int role, number value | int 1=OK | Set a role value on a modbus device |
| mb_start_scan | int start, int end | Initiate an automatic scan of the modbus | |
| md5 | string input | string 32 characters | Calculate the MD5 hash of a string |
| md5_file | string filename | string 32 characters | Calculate the MD5 hash of a file |
| mem_dump | Write the current memory map to /dump.txt | ||
| mem_usage | Write memory usage to standard output | ||
| microtime | int ms | Return the number of milliseconds since boot | |
| mkdir | string pathname | int 0 or error code | Make a directory |
| mktime | int hour, int minute, int second, int month, int day, int year | int seconds | Return the Linux Timestamp for a given date and time |
| mqtt_disconnect | Disconnect MQTT connection | ||
| mqtt_publish | string channel, string content | int 1 for success or 0 for error | Publish a message to an MQTT server |
| mqtt_subscribe | string channel, string callback | int 1 for success or 0 for error | Subscribe to a channel on an MQTT server |
| mqttstat | array array with connection status | Get MQTT Connection status | |
| net_disable3g | Disable 3G support for the dongle | ||
| net_enable3g | Enable 3G support for the dongle | ||
| netstat | array | Get Ethernet information | |
| number_format | mixed number, int digits | string formatted | Return the string value of a number formatted to a particular precision |
| nvram_backup | string filename | int bytes written or 0=error | Backup the contents of NVRAM to a file on the SD Card |
| nvram_defrag | Defragment NVRAM to optimise it | ||
| nvram_dump | Dump the contents of NVRAM to standard output | ||
| nvram_free | int bytes | Return the number of bytes available in NVRAM | |
| nvram_get | string key | mixed value | Get a value from NVRAM |
| nvram_restore | string filename | Restore the contents of NVRAM from a file | |
| nvram_set | string key, string value | int 1=OK | Set a key and value in NVRAM |
| nvram_unset | string key | int 1=OK | Clear a key from NVRAM |
| ord | string character | int ASCII code | Return the ASCII code for a character |
| ow_first | array or int 0 | Initiate a OneWire bus scan and return the address of the first device found | |
| ow_next | array or int 0 | Return the address of the next OneWire device found (after an ow_first) | |
| ow_read | int value or 0 | Read a byte from the OneWire bus | |
| ow_read_temp | array device_id | float degrees Celsius | Read a temperature from a device on the OneWire bus |
| ow_reset | Reset the OneWire bus | ||
| ow_write | int value | Write a byte to the OneWire bus | |
| pack | string format, mixed value | string | Pack a value into a string |
| phpinfo | string | Return information about the system | |
| pin_configure | int pin_index, int pin_type, int counter_type | Configure an I/O pin as a digital input, output, or analog input | |
| pin_get | int pin_index, int pin_type | int value | Return the value of an I/O pin |
| pin_set | int pin_index, int value | Set a digital output to value 1 or 0 | |
| ping | string host | array | Send an ICMP ping and place the result in an array |
| power | number base, number exp | number baseexp | Return base raised to the power of exp |
| string data | Print data to the current output stream such as a web page or terminal | ||
| print_r | array | Dump the contents of an array to the current output | |
| printf | string format, mixed values ... | Print a formatted string to standard output | |
| process_kill | int pid | Send a kill request to a process | |
| process_list | array | Return an array of the currently running scripts | |
| rand | int min, int max | int | Return a random integer between min and max |
| reboot | Reboot the processor | ||
| register_callback | string callback_type, string filename, string functionname | int 0 or error code | Register a callback function for system events |
| rename | string source, string destination | int 0 or error code | Rename or move a file or directory from source to destination |
| reset | Reset the processor | ||
| rmdir | string pathname, int delete_contents | int 0=OK | Remove a directory, with optional deletion of contents |
| send_sms | string phone_number, string message | int result | sends an sms through a cellular dongle |
| session_destroy | Clear the current session's data | ||
| session_is_new | int | Check if a session was just initiated | |
| session_start | Initiate a new session and send the cookie data for it | ||
| set_cert_key | string key,string cert | Set a custom certificate encryption key | |
| set_search_path | string pathname | Set the search path for the telnet client | |
| setethpower | int state | Enable or disable the ethernet controller | |
| setpriority | int priority | Set the priority of the current script | |
| settime | int timestamp, int calibration | Set the system time from a Linux Timestamp, with optional calibration | |
| setusbpower | int state | Enable or disable USB power | |
| sha1 | string input | string 40 characters | Calculate the SHA1 hash of a string |
| sin | number radian_angle | float sine | Return sine of a radian_angle |
| sizeof | array | int number of elements | Return the number of elements in an array |
| sleep | int ms | Sleep for specified milliseconds | |
| snmp_trap_send | string message | int 0 or 1 | Send an SNMP trap message with ASCII content of source |
| spi_clearcs | Clear the CS output of the SPI bus | ||
| spi_read | int byte | Read a byte from the SPI bus | |
| spi_setcs | Set the CS output of the SPI bus | ||
| spi_write | int byte | Write a byte to the SPI bus | |
| sprintf | string format, mixed values ... | string formatted | Return a formatted string |
| sqr | number number | number squared | Return the square of a number |
| sqrt | number number | number square root | Return the square root of a number |
| stats | array | Return system statistics | |
| str_replace | string search, string replace, string subject,[int &count] | string result | Return the string with each occurrence of search replaced with replace |
| strftime | string format, int timestamp | string formatted | Format a Linux Timestamp using a format string |
| strlen | string input | int length | Return the length of a string |
| strpos | string haystack, string needle | int position or -1 | Return the position of the first occurrence of a needle in a haystack |
| strrpos | string haystack, string needle | int position or -1 | Return the position of the last occurrence of a needle in a haystack |
| strtolower | string input | string lowercase | Return the lowercase version of a string |
| strtoupper | string input | string UPPERCASE | Return the UPPERCASE version of a string |
| strval | mixed value | string | Return the string equivalent of a number |
| substr | string input, int start, int length | string substring | Return part of a string |
| sys_get | string parameter|int value | Get a system parameter | |
| sys_set | string parameter,[ int value]|int result | Set a system parameter | |
| tar_finish | int handle| int 1=OK | Add the ending header to a TAR file</html> | |
| tar_put | int handle, string src_pathname, string tar_pathname | int 1=OK | Add a file to an open file in TAR format |
| time | int seconds | Return the current system timestamp | |
| timefromfat | int filetime | int seconds | Convert a FAT filetime to a Linux Timestamp |
| trim | string input | string trimmed | Return the trimmed string |
| ucfirst | string input | string Lowercase | Convert a string to Lowercase except for the first character |
| unlink | string filename | int 0 or error code | Remove a file (delete it) |
| untar | string filename, int verbosity | int 1=OK | Expand a TAR file into the current folder, optionally verbose |
| unpack | string format, string value | number | Unpack a packed string value and return the original data |
| uptime | int ms | Return the uptime in milliseconds | |
| urldecode | string str | string string to encode | URL-Decode a string |
| urlencode | string str | string encoded string | URL-Encode a string |
| wifi_disable | Disable Wifi module | ||
| wifi_enable | Enable Wifi module | ||