API-README 19 KB

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