API-README 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  1. This README contains details about the BFGMiner RPC API
  2. If you start BFGMiner 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 BFGMiner 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 BFGMiner.
  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 BFGMiner 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=BFGMiner 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 status
  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. devdetail DEVS Each available device with their fixed details
  90. e.g. GPU=0,Driver=opencl,Kernel=diablo,Model=...|
  91. gpu|N GPU The details of a single GPU number N in the same
  92. format and details as for DEVS
  93. pga|N PGA The details of a single PGA number N in the same
  94. format and details as for DEVS
  95. This is only available if PGA mining is enabled
  96. Use 'pgacount' or 'config' first to see if there are any
  97. cpu|N CPU The details of a single CPU number N in the same
  98. format and details as for DEVS
  99. This is only available if CPU mining is enabled
  100. Use 'cpucount' or 'config' first to see if there are any
  101. gpucount GPUS Count=N| <- the number of GPUs
  102. pgacount PGAS Count=N| <- the number of PGAs
  103. Always returns 0 if PGA mining is disabled
  104. cpucount CPUS Count=N| <- the number of CPUs
  105. Always returns 0 if CPU mining is disabled
  106. switchpool|N (*)
  107. none There is no reply section just the STATUS section
  108. stating the results of switching pool N to the
  109. highest priority (the pool is also enabled)
  110. The Msg includes the pool URL
  111. enablepool|N (*)
  112. none There is no reply section just the STATUS section
  113. stating the results of enabling pool N
  114. The Msg includes the pool URL
  115. addpool|URL,USR,PASS (*)
  116. none There is no reply section just the STATUS section
  117. stating the results of attempting to add pool N
  118. The Msg includes the pool URL
  119. Use '\\' to get a '\' and '\,' to include a comma
  120. inside URL, USR or PASS
  121. disablepool|N (*)
  122. none There is no reply section just the STATUS section
  123. stating the results of disabling pool N
  124. The Msg includes the pool URL
  125. removepool|N (*)
  126. none There is no reply section just the STATUS section
  127. stating the results of removing pool N
  128. The Msg includes the pool URL
  129. N.B. all details for the pool will be lost
  130. gpuenable|N (*)
  131. none There is no reply section just the STATUS section
  132. stating the results of the enable request
  133. gpudisable|N (*)
  134. none There is no reply section just the STATUS section
  135. stating the results of the disable request
  136. gpurestart|N (*)
  137. none There is no reply section just the STATUS section
  138. stating the results of the restart request
  139. gpuintensity|N,I (*)
  140. none There is no reply section just the STATUS section
  141. stating the results of setting GPU N intensity to I
  142. gpumem|N,V (*)
  143. none There is no reply section just the STATUS section
  144. stating the results of setting GPU N memoryclock to V MHz
  145. gpuengine|N,V (*)
  146. none There is no reply section just the STATUS section
  147. stating the results of setting GPU N clock to V MHz
  148. gpufan|N,V (*)
  149. none There is no reply section just the STATUS section
  150. stating the results of setting GPU N fan speed to V%
  151. gpuvddc|N,V (*)
  152. none There is no reply section just the STATUS section
  153. stating the results of setting GPU N vddc to V
  154. save|filename (*)
  155. none There is no reply section just the STATUS section
  156. stating success or failure saving the BFGMiner config
  157. to filename
  158. The filename is optional and will use the cgminer
  159. default if not specified
  160. quit (*) none There is no status section but just a single "BYE"
  161. reply before BFGMiner quits
  162. notify NOTIFY The last status and history count of each devices problem
  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 BFGMiner
  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 BFGMiner 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 BFGMiner 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 BFGMiner 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 BFGMiner
  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. ----------
  224. API V1.11 (cgminer v2.4.2)
  225. Modified API commands:
  226. 'save' no longer requires a filename (use default if not specified)
  227. 'save' incorrectly returned status E (error) on success before.
  228. It now correctly returns S (success)
  229. ----------
  230. API V1.10 (cgminer v2.4.1)
  231. Added API commands:
  232. 'stats'
  233. N.B. the 'stats' command can change at any time so any specific content
  234. present should not be relied upon.
  235. The data content is mainly used for debugging purposes or hidden options
  236. in cgminer and can change as development work requires
  237. Modified API commands:
  238. 'pools' added "Last Share Time"
  239. ----------
  240. API V1.9 (cgminer v2.4.0)
  241. Added API commands:
  242. 'restart'
  243. Modified API commands:
  244. 'notify' corrected invalid JSON
  245. ----------
  246. API V1.8 (cgminer v2.3.5)
  247. Added API commands:
  248. 'devdetails'
  249. Support for the ZTex FPGA was added
  250. ----------
  251. API V1.7 (cgminer v2.3.4)
  252. Added API commands:
  253. 'removepool'
  254. Modified API commands:
  255. 'pools' added "User"
  256. From API version 1.7 onwards, reply strings in JSON and Text have the
  257. necessary escaping as required to avoid ambiguity
  258. For JSON the 2 characters '"' and '\' are escaped with a '\' before them
  259. For Text the 4 characters '|' ',' '=' and '\' are escaped the same way
  260. ----------
  261. API V1.6 (cgminer v2.3.2)
  262. Added API commands:
  263. 'pga'
  264. 'pgaenable'
  265. 'pgadisable'
  266. 'pgacount'
  267. Modified API commands:
  268. 'devs' now includes Icarus and Bitforce FPGA devices
  269. 'notify' added "*" to the front of the name of all numeric error fields
  270. 'config' correct "Log Interval" to use numeric (not text) type for JSON
  271. Support for Icarus and Bitforce FPGAs was added
  272. ----------
  273. API V1.5 was not released
  274. ----------
  275. API V1.4 (Kano's interim release of cgminer v2.3.1)
  276. Added API commands:
  277. 'notify'
  278. Modified API commands:
  279. 'config' added "Device Code" and "OS"
  280. Added "When" to the STATUS reply section of all commands
  281. ----------
  282. API V1.3 (cgminer v2.3.1-2)
  283. Added API commands:
  284. 'addpool'
  285. Modified API commands:
  286. 'devs'/'gpu' added "Total MH" for each device
  287. 'summary' added "Total MH"
  288. ----------
  289. API V1.2 (cgminer v2.3.0)
  290. Added API commands:
  291. 'enablepool'
  292. 'disablepool'
  293. 'privileged'
  294. Modified API commands:
  295. 'config' added "Log Interval"
  296. Starting with API V1.2, any attempt to access a command that requires
  297. privileged security, from an IP address that does not have privileged
  298. security, will return an "Access denied" Error Status
  299. ----------
  300. API V1.1 (cgminer v2.2.4)
  301. There were no changes to the API commands in cgminer v2.2.4,
  302. however support was added to cgminer for IP address restrictions
  303. with the --api-allow option
  304. ----------
  305. API V1.1 (cgminer v2.2.2)
  306. Prior to V1.1, devs/gpu incorrectly reported GPU0 Intensity for all GPUs
  307. Modified API commands:
  308. 'devs'/'gpu' added "Last Share Pool" and "Last Share Time" for each device
  309. ----------
  310. API V1.0 (cgminer v2.2.0)
  311. Remove default CPU support
  312. Added API commands:
  313. 'config'
  314. 'gpucount'
  315. 'cpucount'
  316. 'switchpool'
  317. 'gpuintensity'
  318. 'gpumem'
  319. 'gpuengine'
  320. 'gpufan'
  321. 'gpuvddc'
  322. 'save'
  323. ----------
  324. API V0.7 (cgminer v2.1.0)
  325. Initial release of the API in the main cgminer git
  326. Commands:
  327. 'version'
  328. 'devs'
  329. 'pools'
  330. 'summary'
  331. 'gpuenable'
  332. 'gpudisable'
  333. 'gpurestart'
  334. 'gpu'
  335. 'cpu'
  336. 'gpucount'
  337. 'cpucount'
  338. 'quit'