API-README 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  1. This README contains details about the cgminer RPC API
  2. If you start cgminer with the "--api-listen" option, it will listen on a
  3. simple TCP/IP socket for single string API requests from the same machine
  4. running cgminer and reply with a string and then close the socket each time
  5. If you add the "--api-network" option, it will accept API requests from any
  6. network attached computer.
  7. You can only access the comands that reply with data in this mode.
  8. By default, you cannot access any privileged command that affects the miner -
  9. you will receive an access denied status message see --api-allow below.
  10. You can specify IP addresses/prefixes that are only allowed to access the API
  11. with the "--api-allow" option e.g. --api-allow W:192.168.0.1,10.0.0/24
  12. will allow 192.168.0.1 or any address matching 10.0.0.*, but nothing else
  13. IP addresses are automatically padded with extra '.0's as needed
  14. Without a /prefix is the same as specifying /32
  15. 0/0 means all IP addresses.
  16. The 'W:' on the front gives that address/subnet privileged access to commands
  17. that modify cgminer.
  18. Without it those commands return an access denied status.
  19. Privileged access is checked in the order the IP addresses were supplied to
  20. "--api-allow"
  21. The first match determines the privilege level.
  22. Using the "--api-allow" option overides the "--api-network" option if they
  23. are both specified
  24. With "--api-allow", 127.0.0.1 is not by default given access unless specified
  25. The RPC API request can be either simple text or JSON.
  26. If the request is JSON (starts with '{'), it will reply with a JSON formatted
  27. response, otherwise it replies with text formatted as described further below.
  28. The JSON request format required is '{"command":"CMD","parameter":"PARAM"}'
  29. (though of course parameter is not required for all requests)
  30. where "CMD" is from the "Request" column below and "PARAM" would be e.g.
  31. the CPU/GPU number if required.
  32. An example request in both formats to set GPU 0 fan to 80%:
  33. gpufan|0,80
  34. {"command":"gpufan","parameter":"0,80"}
  35. The format of each reply (unless stated otherwise) is a STATUS section
  36. followed by an optional detail section
  37. From API version 1.7 onwards, reply strings in JSON and Text have the
  38. necessary escaping as required to avoid ambiguity - they didn't before 1.7
  39. For JSON the 2 characters '"' and '\' are escaped with a '\' before them
  40. For Text the 4 characters '|' ',' '=' and '\' are escaped the same way
  41. Only user entered information will contain characters that require being
  42. escaped, such as Pool URL, User and Password or the Config save filename,
  43. when they are returned in messages or as their values by the API
  44. For API version 1.4 and later:
  45. The STATUS section is:
  46. STATUS=X,When=NNN,Code=N,Msg=string,Description=string|
  47. STATUS=X Where X is one of:
  48. W - Warning
  49. I - Informational
  50. S - Success
  51. E - Error
  52. F - Fatal (code bug)
  53. When=NNN
  54. Standard long time of request in seconds
  55. Code=N
  56. Each unique reply has a unigue Code (See api.c - #define MSG_NNNNNN)
  57. Msg=string
  58. Message matching the Code value N
  59. Description=string
  60. This defaults to the cgminer version but is the value of --api-description
  61. if it was specified at runtime.
  62. For API version 1.9:
  63. The list of requests - a (*) means it requires privileged access - and replies are:
  64. Request Reply Section Details
  65. ------- ------------- -------
  66. version VERSION CGMiner=cgminer version
  67. API=API version
  68. config CONFIG Some miner configuration information:
  69. GPU Count=N, <- the number of GPUs
  70. PGA Count=N, <- the number of PGAs
  71. CPU Count=N, <- the number of CPUs
  72. Pool Count=N, <- the number of Pools
  73. ADL=X, <- Y or N if ADL is compiled in the code
  74. ADL in use=X, <- Y or N if any GPU has ADL
  75. Strategy=Name, <- the current pool strategy
  76. Log Interval=N, <- log interval (--log N)
  77. Device Code=GPU ICA | <- spaced list of compiled devices
  78. summary SUMMARY The status summary of the miner
  79. e.g. Elapsed=NNN,Found Blocks=N,Getworks=N,...|
  80. pools POOLS The status of each pool
  81. e.g. Pool=0,URL=http://pool.com:6311,Status=Alive,...|
  82. devs DEVS Each available GPU, PGA and CPU with their details
  83. e.g. GPU=0,Accepted=NN,MHS av=NNN,...,Intensity=D|
  84. Last Share Time=NNN, <- standand long time in seconds
  85. (or 0 if none) of last accepted share
  86. Last Share Pool=N, <- pool number (or -1 if none)
  87. Will not report PGAs if PGA mining is disabled
  88. Will not report CPUs if CPU mining is disabled
  89. gpu|N GPU The details of a single GPU number N in the same
  90. format and details as for DEVS
  91. pga|N PGA The details of a single PGA number N in the same
  92. format and details as for DEVS
  93. This is only available if PGA mining is enabled
  94. Use 'pgacount' or 'config' first to see if there are any
  95. cpu|N CPU The details of a single CPU number N in the same
  96. format and details as for DEVS
  97. This is only available if CPU mining is enabled
  98. Use 'cpucount' or 'config' first to see if there are any
  99. gpucount GPUS Count=N| <- the number of GPUs
  100. pgacount PGAS Count=N| <- the number of PGAs
  101. Always returns 0 if PGA mining is disabled
  102. cpucount CPUS Count=N| <- the number of CPUs
  103. Always returns 0 if CPU mining is disabled
  104. switchpool|N (*)
  105. none There is no reply section just the STATUS section
  106. stating the results of switching pool N to the
  107. highest priority (the pool is also enabled)
  108. The Msg includes the pool URL
  109. enablepool|N (*)
  110. none There is no reply section just the STATUS section
  111. stating the results of enabling pool N
  112. The Msg includes the pool URL
  113. addpool|URL,USR,PASS (*)
  114. none There is no reply section just the STATUS section
  115. stating the results of attempting to add pool N
  116. The Msg includes the pool URL
  117. Use '\\' to get a '\' and '\,' to include a comma
  118. inside URL, USR or PASS
  119. disablepool|N (*)
  120. none There is no reply section just the STATUS section
  121. stating the results of disabling pool N
  122. The Msg includes the pool URL
  123. removepool|N (*)
  124. none There is no reply section just the STATUS section
  125. stating the results of removing pool N
  126. The Msg includes the pool URL
  127. N.B. all details for the pool will be lost
  128. gpuenable|N (*)
  129. none There is no reply section just the STATUS section
  130. stating the results of the enable request
  131. gpudisable|N (*)
  132. none There is no reply section just the STATUS section
  133. stating the results of the disable request
  134. gpurestart|N (*)
  135. none There is no reply section just the STATUS section
  136. stating the results of the restart request
  137. gpuintensity|N,I (*)
  138. none There is no reply section just the STATUS section
  139. stating the results of setting GPU N intensity to I
  140. gpumem|N,V (*)
  141. none There is no reply section just the STATUS section
  142. stating the results of setting GPU N memoryclock to V MHz
  143. gpuengine|N,V (*)
  144. none There is no reply section just the STATUS section
  145. stating the results of setting GPU N clock to V MHz
  146. gpufan|N,V (*)
  147. none There is no reply section just the STATUS section
  148. stating the results of setting GPU N fan speed to V%
  149. gpuvddc|N,V (*)
  150. none There is no reply section just the STATUS section
  151. stating the results of setting GPU N vddc to V
  152. save|filename (*)
  153. none There is no reply section just the STATUS section
  154. stating success or failure saving the cgminer config
  155. to filename
  156. quit (*) none There is no status section but just a single "BYE"
  157. reply before cgminer quits
  158. notify NOTIFY The last status and history count of each devices problem
  159. This lists all devices including those not supported
  160. by the 'devs' command
  161. e.g. NOTIFY=0,Name=GPU,ID=0,Last Well=1332432290,...|
  162. privileged (*)
  163. none There is no reply section just the STATUS section
  164. stating an error if you do not have privileged access
  165. to the API and success if you do have privilege
  166. The command doesn't change anything in cgminer
  167. pgaenable|N (*)
  168. none There is no reply section just the STATUS section
  169. stating the results of the enable request
  170. You cannot enable a PGA if it's status is not WELL
  171. This is only available if PGA mining is enabled
  172. pgadisable|N (*)
  173. none There is no reply section just the STATUS section
  174. stating the results of the disable request
  175. This is only available if PGA mining is enabled
  176. devdetails DEVDETAILS Each device with a list of their static details
  177. This lists all devices including those not supported
  178. by the 'devs' command
  179. e.g. DEVDETAILS=0,Name=GPU,ID=0,Driver=opencl,...|
  180. restart (*) none There is no status section but just a single "RESTART"
  181. reply before cgminer restarts
  182. stats STATS Each device or pool that has 1 or more getworks
  183. with a list of stats regarding getwork times
  184. The values returned by stats may change in future
  185. versions thus would not normally be displayed
  186. Device drivers are also able to add stats to the
  187. end of the details returned
  188. When you enable, disable or restart a GPU or PGA, you will also get Thread messages
  189. in the cgminer status window
  190. When you switch to a different pool to the current one, you will get a
  191. 'Switching to URL' message in the cgminer status windows
  192. Obviously, the JSON format is simply just the names as given before the '='
  193. with the values after the '='
  194. If you enable cgminer debug (-D or --debug) you will also get messages showing
  195. details of the requests received and the replies
  196. There are included 4 program examples for accessing the API:
  197. api-example.php - a php script to access the API
  198. usAge: php api-example.php command
  199. by default it sends a 'summary' request to the miner at 127.0.0.1:4028
  200. If you specify a command it will send that request instead
  201. You must modify the line "$socket = getsock('127.0.0.1', 4028);" at the
  202. beginning of "function request($cmd)" to change where it looks for cgminer
  203. API.java/API.class
  204. a java program to access the API (with source code)
  205. usAge is: java API command address port
  206. Any missing or blank parameters are replaced as if you entered:
  207. java API summary 127.0.0.1 4028
  208. api-example.c - a 'C' program to access the API (with source code)
  209. usAge: api-example [command [ip/host [port]]]
  210. again, as above, missing or blank parameters are replaced as if you entered:
  211. api-example summary 127.0.0.1 4028
  212. miner.php - an example web page to access the API
  213. This includes buttons and inputs to attempt access to the privileged commands
  214. Read the top of the file (miner.php) for details of how to tune the display
  215. and also to use the option to display a multi-rig summary
  216. ----------
  217. Feature Changelog for external applications using the API:
  218. API V1.10
  219. Added API commands:
  220. 'stats'
  221. N.B. the 'stats' command can change at any time so any specific content
  222. present should not be relied upon.
  223. The data content is mainly used for debugging purposes or hidden options
  224. in cgminer and can change as development work requires
  225. Modified API commands:
  226. 'pools' added "Last Share Time"
  227. ----------
  228. API V1.9 (cgminer v2.4.0)
  229. Added API commands:
  230. 'restart'
  231. Modified API commands:
  232. 'notify' corrected invalid JSON
  233. ----------
  234. API V1.8 (cgminer v2.3.5)
  235. Added API commands:
  236. 'devdetails'
  237. Support for the ZTex FPGA was added
  238. ----------
  239. API V1.7 (cgminer v2.3.4)
  240. Added API commands:
  241. 'removepool'
  242. Modified API commands:
  243. 'pools' added "User"
  244. From API version 1.7 onwards, reply strings in JSON and Text have the
  245. necessary escaping as required to avoid ambiguity
  246. For JSON the 2 characters '"' and '\' are escaped with a '\' before them
  247. For Text the 4 characters '|' ',' '=' and '\' are escaped the same way
  248. ----------
  249. API V1.6 (cgminer v2.3.2)
  250. Added API commands:
  251. 'pga'
  252. 'pgaenable'
  253. 'pgadisable'
  254. 'pgacount'
  255. Modified API commands:
  256. 'devs' now includes Icarus and Bitforce FPGA devices
  257. 'notify' added "*" to the front of the name of all numeric error fields
  258. 'config' correct "Log Interval" to use numeric (not text) type for JSON
  259. Support for Icarus and Bitforce FPGAs was added
  260. ----------
  261. API V1.5 was not released
  262. ----------
  263. API V1.4 (Kano's interim release of cgminer v2.3.1)
  264. Added API commands:
  265. 'notify'
  266. Modified API commands:
  267. 'config' added "Device Code" and "OS"
  268. Added "When" to the STATUS reply section of all commands
  269. ----------
  270. API V1.3 (cgminer v2.3.1-2)
  271. Added API commands:
  272. 'addpool'
  273. Modified API commands:
  274. 'devs'/'gpu' added "Total MH" for each device
  275. 'summary' added "Total MH"
  276. ----------
  277. API V1.2 (cgminer v2.3.0)
  278. Added API commands:
  279. 'enablepool'
  280. 'disablepool'
  281. 'privileged'
  282. Modified API commands:
  283. 'config' added "Log Interval"
  284. Starting with API V1.2, any attempt to access a command that requires
  285. privileged security, from an IP address that does not have privileged
  286. security, will return an "Access denied" Error Status
  287. ----------
  288. API V1.1 (cgminer v2.2.4)
  289. There were no changes to the API commands in cgminer v2.2.4,
  290. however support was added to cgminer for IP address restrictions
  291. with the --api-allow option
  292. ----------
  293. API V1.1 (cgminer v2.2.2)
  294. Prior to V1.1, devs/gpu incorrectly reported GPU0 Intensity for all GPUs
  295. Modified API commands:
  296. 'devs'/'gpu' added "Last Share Pool" and "Last Share Time" for each device
  297. ----------
  298. API V1.0 (cgminer v2.2.0)
  299. Remove default CPU support
  300. Added API commands:
  301. 'config'
  302. 'gpucount'
  303. 'cpucount'
  304. 'switchpool'
  305. 'gpuintensity'
  306. 'gpumem'
  307. 'gpuengine'
  308. 'gpufan'
  309. 'gpuvddc'
  310. 'save'
  311. ----------
  312. API V0.7 (cgminer v2.1.0)
  313. Initial release of the API in the main cgminer git
  314. Commands:
  315. 'version'
  316. 'devs'
  317. 'pools'
  318. 'summary'
  319. 'gpuenable'
  320. 'gpudisable'
  321. 'gpurestart'
  322. 'gpu'
  323. 'cpu'
  324. 'gpucount'
  325. 'cpucount'
  326. 'quit'