API-README 18 KB

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