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