API-README 16 KB

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