API-README 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513
  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:*
  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. disablepool|N (*)
  140. none There is no reply section just the STATUS section
  141. stating the results of disabling pool N
  142. The Msg includes the pool URL
  143. removepool|N (*)
  144. none There is no reply section just the STATUS section
  145. stating the results of removing pool N
  146. The Msg includes the pool URL
  147. N.B. all details for the pool will be lost
  148. gpuenable|N (*)
  149. none There is no reply section just the STATUS section
  150. stating the results of the enable request
  151. gpudisable|N (*)
  152. none There is no reply section just the STATUS section
  153. stating the results of the disable request
  154. gpurestart|N (*)
  155. none There is no reply section just the STATUS section
  156. stating the results of the restart request
  157. gpuintensity|N,I (*)
  158. none There is no reply section just the STATUS section
  159. stating the results of setting GPU N intensity to I
  160. gpumem|N,V (*)
  161. none There is no reply section just the STATUS section
  162. stating the results of setting GPU N memoryclock to V MHz
  163. gpuengine|N,V (*)
  164. none There is no reply section just the STATUS section
  165. stating the results of setting GPU N clock to V MHz
  166. gpufan|N,V (*)
  167. none There is no reply section just the STATUS section
  168. stating the results of setting GPU N fan speed to V%
  169. gpuvddc|N,V (*)
  170. none There is no reply section just the STATUS section
  171. stating the results of setting GPU N vddc to V
  172. save|filename (*)
  173. none There is no reply section just the STATUS section
  174. stating success or failure saving the cgminer config
  175. to filename
  176. The filename is optional and will use the cgminer
  177. default if not specified
  178. quit (*) none There is no status section but just a single "BYE"
  179. reply before cgminer quits
  180. notify NOTIFY The last status and history count of each devices problem
  181. This lists all devices including those not supported
  182. by the 'devs' command
  183. e.g. NOTIFY=0,Name=GPU,ID=0,Last Well=1332432290,...|
  184. privileged (*)
  185. none There is no reply section just the STATUS section
  186. stating an error if you do not have privileged access
  187. to the API and success if you do have privilege
  188. The command doesn't change anything in cgminer
  189. pgaenable|N (*)
  190. none There is no reply section just the STATUS section
  191. stating the results of the enable request
  192. You cannot enable a PGA if it's status is not WELL
  193. This is only available if PGA mining is enabled
  194. pgadisable|N (*)
  195. none There is no reply section just the STATUS section
  196. stating the results of the disable request
  197. This is only available if PGA mining is enabled
  198. devdetails DEVDETAILS Each device with a list of their static details
  199. This lists all devices including those not supported
  200. by the 'devs' command
  201. e.g. DEVDETAILS=0,Name=GPU,ID=0,Driver=opencl,...|
  202. restart (*) none There is no status section but just a single "RESTART"
  203. reply before cgminer restarts
  204. stats STATS Each device or pool that has 1 or more getworks
  205. with a list of stats regarding getwork times
  206. The values returned by stats may change in future
  207. versions thus would not normally be displayed
  208. Device drivers are also able to add stats to the
  209. end of the details returned
  210. check|cmd COMMAND Exists=Y/N, <- 'cmd' exists in this version
  211. Access=Y/N| <- you have access to use 'cmd'
  212. When you enable, disable or restart a GPU or PGA, you will also get Thread messages
  213. in the cgminer status window
  214. When you switch to a different pool to the current one, you will get a
  215. 'Switching to URL' message in the cgminer status windows
  216. Obviously, the JSON format is simply just the names as given before the '='
  217. with the values after the '='
  218. If you enable cgminer debug (-D or --debug) you will also get messages showing
  219. details of the requests received and the replies
  220. There are included 4 program examples for accessing the API:
  221. api-example.php - a php script to access the API
  222. usAge: php api-example.php command
  223. by default it sends a 'summary' request to the miner at 127.0.0.1:4028
  224. If you specify a command it will send that request instead
  225. You must modify the line "$socket = getsock('127.0.0.1', 4028);" at the
  226. beginning of "function request($cmd)" to change where it looks for cgminer
  227. API.java/API.class
  228. a java program to access the API (with source code)
  229. usAge is: java API command address port
  230. Any missing or blank parameters are replaced as if you entered:
  231. java API summary 127.0.0.1 4028
  232. api-example.c - a 'C' program to access the API (with source code)
  233. usAge: api-example [command [ip/host [port]]]
  234. again, as above, missing or blank parameters are replaced as if you entered:
  235. api-example summary 127.0.0.1 4028
  236. miner.php - an example web page to access the API
  237. This includes buttons and inputs to attempt access to the privileged commands
  238. Read the top of the file (miner.php) for details of how to tune the display
  239. and also to use the option to display a multi-rig summary
  240. ----------
  241. Feature Changelog for external applications using the API:
  242. API V1.14
  243. Modified API commands:
  244. 'stats' - more icarus timing stats added
  245. 'notify' - include new device comms error counter
  246. The internal code for handling data was rewritten (~25% of the code)
  247. Completely backward compatible
  248. ----------
  249. API V1.13 (cgminer v2.4.4)
  250. Added API commands:
  251. 'check'
  252. Support was added to cgminer for API access groups with the --api-groups option
  253. It's 100% backward compatible with previous --api-access commands
  254. ----------
  255. API V1.12 (cgminer v2.4.3)
  256. Modified API commands:
  257. 'stats' - more pool stats added
  258. Support for the ModMinerQuad FPGA was added
  259. ----------
  260. API V1.11 (cgminer v2.4.2)
  261. Modified API commands:
  262. 'save' no longer requires a filename (use default if not specified)
  263. 'save' incorrectly returned status E (error) on success before.
  264. It now correctly returns S (success)
  265. ----------
  266. API V1.10 (cgminer v2.4.1)
  267. Added API commands:
  268. 'stats'
  269. N.B. the 'stats' command can change at any time so any specific content
  270. present should not be relied upon.
  271. The data content is mainly used for debugging purposes or hidden options
  272. in cgminer and can change as development work requires
  273. Modified API commands:
  274. 'pools' added "Last Share Time"
  275. ----------
  276. API V1.9 (cgminer v2.4.0)
  277. Added API commands:
  278. 'restart'
  279. Modified API commands:
  280. 'notify' corrected invalid JSON
  281. ----------
  282. API V1.8 (cgminer v2.3.5)
  283. Added API commands:
  284. 'devdetails'
  285. Support for the ZTex FPGA was added
  286. ----------
  287. API V1.7 (cgminer v2.3.4)
  288. Added API commands:
  289. 'removepool'
  290. Modified API commands:
  291. 'pools' added "User"
  292. From API version 1.7 onwards, reply strings in JSON and Text have the
  293. necessary escaping as required to avoid ambiguity
  294. For JSON the 2 characters '"' and '\' are escaped with a '\' before them
  295. For Text the 4 characters '|' ',' '=' and '\' are escaped the same way
  296. ----------
  297. API V1.6 (cgminer v2.3.2)
  298. Added API commands:
  299. 'pga'
  300. 'pgaenable'
  301. 'pgadisable'
  302. 'pgacount'
  303. Modified API commands:
  304. 'devs' now includes Icarus and Bitforce FPGA devices
  305. 'notify' added "*" to the front of the name of all numeric error fields
  306. 'config' correct "Log Interval" to use numeric (not text) type for JSON
  307. Support for Icarus and Bitforce FPGAs was added
  308. ----------
  309. API V1.5 was not released
  310. ----------
  311. API V1.4 (Kano's interim release of cgminer v2.3.1)
  312. Added API commands:
  313. 'notify'
  314. Modified API commands:
  315. 'config' added "Device Code" and "OS"
  316. Added "When" to the STATUS reply section of all commands
  317. ----------
  318. API V1.3 (cgminer v2.3.1-2)
  319. Added API commands:
  320. 'addpool'
  321. Modified API commands:
  322. 'devs'/'gpu' added "Total MH" for each device
  323. 'summary' added "Total MH"
  324. ----------
  325. API V1.2 (cgminer v2.3.0)
  326. Added API commands:
  327. 'enablepool'
  328. 'disablepool'
  329. 'privileged'
  330. Modified API commands:
  331. 'config' added "Log Interval"
  332. Starting with API V1.2, any attempt to access a command that requires
  333. privileged security, from an IP address that does not have privileged
  334. security, will return an "Access denied" Error Status
  335. ----------
  336. API V1.1 (cgminer v2.2.4)
  337. There were no changes to the API commands in cgminer v2.2.4,
  338. however support was added to cgminer for IP address restrictions
  339. with the --api-allow option
  340. ----------
  341. API V1.1 (cgminer v2.2.2)
  342. Prior to V1.1, devs/gpu incorrectly reported GPU0 Intensity for all GPUs
  343. Modified API commands:
  344. 'devs'/'gpu' added "Last Share Pool" and "Last Share Time" for each device
  345. ----------
  346. API V1.0 (cgminer v2.2.0)
  347. Remove default CPU support
  348. Added API commands:
  349. 'config'
  350. 'gpucount'
  351. 'cpucount'
  352. 'switchpool'
  353. 'gpuintensity'
  354. 'gpumem'
  355. 'gpuengine'
  356. 'gpufan'
  357. 'gpuvddc'
  358. 'save'
  359. ----------
  360. API V0.7 (cgminer v2.1.0)
  361. Initial release of the API in the main cgminer git
  362. Commands:
  363. 'version'
  364. 'devs'
  365. 'pools'
  366. 'summary'
  367. 'gpuenable'
  368. 'gpudisable'
  369. 'gpurestart'
  370. 'gpu'
  371. 'cpu'
  372. 'gpucount'
  373. 'cpucount'
  374. 'quit'