Pages:
Author

Topic: COMPLETED: Request for an RPC capable fork of cgminer (155 BTC pledged and paid) - page 5. (Read 19433 times)

donator
Activity: 798
Merit: 500
Is this being paid out yet or still testing?
legendary
Activity: 4634
Merit: 1851
Linux since 1997 RedHat 4
Minor change to miner.php - the simple web page that uses the API
(headers are a darker background and a few of the values are formatted)
https://github.com/kanoi/cgminer/commit/da798519b0a2b8c98aea31923f85e4074888757d
legendary
Activity: 4634
Merit: 1851
Linux since 1997 RedHat 4
No - it was me - but you seemed to be the best person to ask Smiley
(it's something I've been thinking about since after I made that last change)
donator
Activity: 1218
Merit: 1079
Gerald Davis
Note to DeathAndTaxes if you see this:
I keep thinking about the "MHS 5s" fields.
That means you already have the field description correct, however, you can't search for it by full name, since it's name will change to match --log
So if --log is 7 the field will be called "MHS 7s"
Is that OK?
Or would you prefer 2 fields instead something like: MHS Ns=1234.99 and Log Interval=5
Thus you can directly index access the field with "MHS Ns"
(or both these 2 and the old 1)

Um you sure it was me?  I haven't looked at the MHS fields yet.  Sorry coming back from a cruise, and getting caught up at work is brutal.  Hopefully I can get a chance to look at it tonight.
legendary
Activity: 4634
Merit: 1851
Linux since 1997 RedHat 4
Yeah looks OK. I guess Smiley
Edit: no actually the SUMMARY one is messed up there's only supposed to be 2 sections "STATUS" and "SUMMARY"

One thing I noticed up front is that you are running an older version of cgminer - the newest version uses full descriptions for the field names.
Current one is 2.0.8y
It also has no exception to the rule of the reply format
(earlier there was an exception to the rule: 'apiversion' - that's gone and now there is only 'version' which uses the same format as the rest)
... and it shows more GPU details that were missing before.

Note to DeathAndTaxes if you see this:
I keep thinking about the "MHS 5s" fields.
That means you already have the field description correct, however, you can't search for it by full name, since it's name will change to match --log
So if --log is 7 the field will be called "MHS 7s"
Is that OK?
Or would you prefer 2 fields instead something like: MHS Ns=1234.99 and Log Interval=5
Thus you can directly index access the field with "MHS Ns"
(or both these 2 and the old 1)
legendary
Activity: 980
Merit: 1008
I tried translating your PHP example directly to Python. Does this look right?

Code:
'STATUS=S,CODE=11,MSG=Summary|SUMMARY=all,EL=42875,ALGO=sse2_64,MHS=722.96,SOL=583,Q=59563,A=517,R=66,HW=0,U=0.72,DW=10075,STATUS=S,CODE=11,MSG=Summary|SUMMARY=all,EL=42875,ALGO=sse2_64,MHS=722.96,SOL=583,Q=59563,A=517,R=66,HW=0,U=0.72,DW=10075,ST=0,GF=65,LW=0,RO=0,BC=2801|'
becomes
{'STATUS': {'STATUS': 'S', 'MSG': 'Summary', 'CODE': '11'}, 1: {'A': '517', 'EL': '42875', 'RO': '0', 'LW': '0', 'BC': '2801', 'SOL': '583', 'SUMMARY': 'all', 'Q': '59563', 'GF': '65', 'R': '66', 'U': '0.72', 'ALGO': 'sse2_64', 'DW': '10075', 'HW': '0', 'ST': '0', 'MHS': '722.96'}, 'SUMMARY': {'A': '517', 'EL': '42875', 'CODE': '11', 'STATUS': 'S', 'SOL': '583', 'SUMMARY': 'all', 'Q': '59563', 'R': '66', 'U': '0.72', 'ALGO': 'sse2_64', 'MSG': 'Summary', 'DW': '10075', 'HW': '0', 'MHS': '722.96'}}

'STATUS=S,CODE=17,MSG=GPU1|GPU=1,GT=69.00,FR=2575,FP=56,EN=Y,STA=ALIVE,MHS=365.10,A=271,R=19,HW=0,U=0.38,I=9|'
becomes
{'STATUS': {'STATUS': 'S', 'MSG': 'GPU1', 'CODE': '17'}, 'GPU1': {'FP': '56', 'A': '271', 'FR': '2575', 'GT': '69.00', 'STA': 'ALIVE', 'I': '9', 'HW': '0', 'EN': 'Y', 'U': '0.38', 'GPU': '1', 'R': '19', 'MHS': '365.10'}}

'STATUS=S,CODE=20,MSG=GPU count|GPUS,COUNT=2|'
becomes
{'STATUS': {'STATUS': 'S', 'MSG': 'GPU count', 'CODE': '20'}, 'GPUS': {0: 'GPUS', 'COUNT': '2'}}

EDIT: The code is this:
Code:
def parseResponse(message):
   data = {}
   objs = message.split('|')

   for obj in objs:
      if (len(obj) > 0):
         items = obj.split(',')
         item = items[0]
         item_id = items[0].split('=', 1)
         if (len(item_id) == 1 or not item_id[1].isdigit()):
            name = item_id[0]
         else:
            name = item_id[0] + item_id[1]

         if (len(name) == 0):
            name = "null"     

         if (name in data):
            num = 1
            while ((name+str(num)) in data):
               num =+ 1
            name =+ str(num)

         counter = 0

         for item in items:
            item_id = item.split('=', 2)
            if not (name in data):
               data[name] = {}
            if (len(item_id) == 2):
               data[name][item_id[0]] = item_id[1]
            else:
               data[name][counter] = item_id[0]

         counter =+ 1

   return data
legendary
Activity: 4634
Merit: 1851
Linux since 1997 RedHat 4
Actually ... I've written and supplied the basics in C, Java and PHP ...
If you can't work out the VERY simple code to parse the output from one of those 3 languages, then ...

As I've said before, if anyone wants JSON they can add to the bounty.
No one replied (fortunately) so it hasn't been added.
I also said that if anyone was already listed in the bounty for me; then if they want it I guess I'll add it for them.
Again, no reply to that either so JSON is out Smiley
legendary
Activity: 980
Merit: 1008
First of all, thank you for extending cgminer with this functionality! I'm planning on using it to control my Bitcoin Radiator (yes, that's right, stay tuned for updates), so it comes in handy for me. With regards to JSON, I disagree a bit on your position, but don't take that as me not appreciating your work.

Though ... if someone actually has some really unexpected need for a JSON format response ...
(I can think of no reason, since this format is way easier to read and parse but has a detail level equivalent to JSON for this requirement)
One reason for the JSON format would be that most languages has an implementation of it already. Thus no JSON parsing would be written, it would be handled by a separate library that has been written already. The following line in Python would replace a custom implementation of parsing your custom format:

Code:
obj = json.load(msg)

So I guess the reason to choose the JSON format is because it reduces redundancy. Chances are that in whichever language one chooses to write an application that wants to control cgminer, this language already has a JSON parsing implementation. You've written an implementation of your format in php, I'll have to write an implementation in Python, and someone who wants to use Ruby will have to write an implementation in Ruby, and so on and so forth for C, C++, Perl, bash, JavaScript, etc.
legendary
Activity: 980
Merit: 1008
It's a socket, not a web server Smiley

http://docs.python.org/howto/sockets.html

[...]
Thank you Sir! I will be looking in to that.

netstat -na displays a listening cgminer. It seems it was the missing -a switch that made it not show sockets on localhost.

By the way, is this the most official description of the various API functions, or is there another place for that documentation?
sr. member
Activity: 349
Merit: 250
Kano,

Sorry about the long wait, I'm going to test this as soon as I can find some time... Hopefully this evening or tomorrow ;-)
donator
Activity: 1218
Merit: 1079
Gerald Davis
Kano,
I just got back from my vacation.  Hopefully tonight or tomorrow I will be able to test latest version.  Looks good so far.
legendary
Activity: 4634
Merit: 1851
Linux since 1997 RedHat 4
It's a socket, not a web server Smiley

http://docs.python.org/howto/sockets.html

If you look at the php, java or C code, you'll see that it's a simple TCP socket you connect to, send one string (the command), receive a reply and then close the socket.
Very quick and very simple.
That link above should help you with the 4 commands necessary to do that.
(plus one to initialise the socket)

On the miner
 sudo netstat -na | grep 4028
should give 2 different responses if you used --api-listen

1) If you have also used --api-network:
  tcp        0      0 0.0.0.0:4028            0.0.0.0:*               LISTEN

2) If you haven't also used --api-network:
  tcp        0      0 127.0.0.1:4028          0.0.0.0:*               LISTEN
legendary
Activity: 980
Merit: 1008
What would be a good way of connecting to cgminer in Python code? I tried using this example from the Bitcoin client. But I get a "Connection reset by peer" error:

Code:
>>> from jsonrpc import ServiceProxy
>>> access = ServiceProxy("http://127.0.0.1:4028")
>>> access.getinfo()
Traceback (most recent call last):
  File "", line 1, in
  File "jsonrpc/proxy.py", line 42, in __call__
    respdata = urllib.urlopen(self.__serviceURL, postdata).read()
  File "/usr/lib/python2.7/urllib.py", line 86, in urlopen
    return opener.open(url, data)
  File "/usr/lib/python2.7/urllib.py", line 207, in open
    return getattr(self, name)(url, data)
  File "/usr/lib/python2.7/urllib.py", line 343, in open_http
    errcode, errmsg, headers = h.getreply()
  File "/usr/lib/python2.7/httplib.py", line 1099, in getreply
    response = self._conn.getresponse()
  File "/usr/lib/python2.7/httplib.py", line 1027, in getresponse
    response.begin()
  File "/usr/lib/python2.7/httplib.py", line 407, in begin
    version, status, reason = self._read_status()
  File "/usr/lib/python2.7/httplib.py", line 365, in _read_status
    line = self.fp.readline()
  File "/usr/lib/python2.7/socket.py", line 430, in readline
    data = recv(1)
IOError: [Errno socket error] [Errno 104] Connection reset by peer
>>> access = ServiceProxy("http://127.0.0.1:4028")

cgminer 2.0.8y is running and it says "API running in restricted access mode" in the log. "netstat -n|grep 4028" doesn't show any output (should it?).
hero member
Activity: 956
Merit: 1001
kano,

I'm going to start installing this on a few of my rigs.  I should have some feedback for you soon Smiley
legendary
Activity: 4634
Merit: 1851
Linux since 1997 RedHat 4
Adjusted MHS version (2.0.8y) now in my git downloads:
https://github.com/kanoi/cgminer/downloads

(source in the git as usual)

This shows the MHS fields as "MHS av" for SUMMARY
For CPU and GPU it shows "MHS av" and "MHS 5s"
(though the '5' in '5s' is actually whatever the "--log|-l " is set to - it defaults to 5)

Also the API version is 0.6 for 2.0.8y

I've put up 3 versions downloadable:
linux 2.0.8y GPU miner
windows 2.0.8y GPU miner
windows 2.0.8y CPU miner (this is the one I test, the above one is just this with GPU enabled that I can't test)
legendary
Activity: 4634
Merit: 1851
Linux since 1997 RedHat 4
As soon as you like Cheesy Cheesy

But yeah I'll make one more change myself as I said above (the MHS fields need 'adjusting')

Of course it won't get into the main git until it's ready to go there so the sooner everyone actually checks it and says nothing is missing the sooner everyone can pay the first part of the bounty and thus the sooner I can pass it onto ckolivas to add it to his git and then you can pay him too Smiley

Just noticed in the first post - it's 125 BTC + 30 BTC not 120+30 Smiley
hero member
Activity: 742
Merit: 500
Looking great.  When I get a chance (probably this weekend), I will get it running on my miner.

I'm assuming we pay the bounty once its stable?
legendary
Activity: 4634
Merit: 1851
Linux since 1997 RedHat 4
Sheesh there really isn't much interest?

Anyway - rather than just having an API I decided to write a PHP web page that uses the API
Very simple (though of course I may make some minor future changes)
Main reason was so I could actually look at it via a web page Tongue

It's in my git: miner.php ( https://github.com/kanoi/cgminer/blob/master/miner.php )

Now some help to actually use it Smiley

Firstly I'll assume you are using xubuntu and my linux install script.
If not, well then wipe your miner and start again with my install script Cheesy Cheesy
Or work it out yourself but it should be similar.

Anyway, with xubuntu 11.04:

start cgminer with the extra red options:
 cgminer -c kanocoin.conf --auto-cpu --auto-gpu -I 9 --api-listen --api-description "My Miner PC"
(of course you can call it whatever you like ...)

(this takes up about 50Mb of USB space)
 sudo apt-get install apache2
 sudo apt-get install php5
 sudo /etc/init.d/apache2 reload

Then copy miner.php into /var/www/
something like:
 sudo cp miner.php /var/www/
From the directory wherever you managed to copy miner.php

Then view the page with something like: http://computerIP/miner.php
(where computerIP is of course the IP address of the miner computer)

If you were wondering what the actual IP address of the miner is:
 sudo ifconfig
It should usually be the 2nd line of 'eth0' after it says 'inet addr:'

You can of course also use the miner.php running on any computer on your network that has apache and php ...
as long as you also add --api-network to cgminer when you run it.
Then also set the '$miner' variable at the top of miner.php to the address of the PC running cgminer

Free extra Smiley YMMV

Edit: hmm I think I need to revise the "MHS" fields in the API output.
I'll change them soon - to show/add "MHS av" and "MHS 5s"  wherever possible
legendary
Activity: 4634
Merit: 1851
Linux since 1997 RedHat 4
OK windows binary 2.0.8x in my git download now also https://github.com/kanoi/cgminer/downloads
Use the two 2.0.8w DLLs there if you don't already have them.

All source updated in my GIT also https://github.com/kanoi/cgminer

Made one extra change that removes the need for the 2 extra inet_* functions I added coz they were missing from windows, but there are others that do the same job that do exist in windows (and linux of course)
and I also found that the code might? have been causing issues with connecting so that may have been DeathAndTaxes problem also - though it worked fine on my XP-Home before so I'm not exactly sure if that was the cause

This is now ready as far as I can tell.
Anything else missing?

The last thing left for me to do is update the doc files - but I'll do that when it's clear it's got all the required code done.
legendary
Activity: 4634
Merit: 1851
Linux since 1997 RedHat 4
My git ( https://github.com/kanoi/cgminer ) has been updated with the changes:
(called it 2.0.8x)

Renamed the 'apiversion' command to just 'version' and it now returns a structure like the rest - now with 2 fields:
   [CGMiner] => 2.0.8x
   [API] => 0.5

Changed all the return field names everywhere to be descriptions (except 2: URL, MHS)

Added all the other ADL GPU properties that cgminer knows to the GPU status fields
(GPU Clock, Memory Clock, GPU Voltage, GPU Activity, Powertune)
Not sure why I forgot them before Tongue

Added a new cgminer option: --api-description
This is added to the end of the STATUS section of all replies as [Description] => string
(default is the software version, currently cgminer 2.0.8x)

In the downloads section on my git I've uploaded the cgminer-2.0.8x version of the Linux executable (replacing the cgminer-2.0.8w version)

I'll try to make a windows binary tomorrow.
Pages:
Jump to: