element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Members
    Members
    • Benefits of Membership
    • Achievement Levels
    • Members Area
    • Personal Blogs
    • Feedback and Support
    • What's New on element14
  • Learn
    Learn
    • Learning Center
    • eBooks
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Dev Tools
    • Manufacturers
    • Raspberry Pi
    • RoadTests & Reviews
    • Avnet Boards Community
    • Product Groups
  • Store
    Store
    • Visit Your Store
    • Choose Another Store
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
Personal Blogs
  • Members
  • More
Personal Blogs
Legacy Personal Blogs Raspberry Pi BOINC Client from Project Mooninite
  • Blog
  • Documents
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Blog Post Actions
  • Subscribe by email
  • More
  • Cancel
  • Share
  • Subscribe by email
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: airbornesurfer
  • Date Created: 19 Jun 2019 4:44 AM Date Created
  • Views 384 views
  • Likes 5 likes
  • Comments 0 comments
  • boinc
  • python
  • seti@home
  • raspberry pi
  • element14 presents
  • asteroid tracker
  • project mooninite
Related
Recommended

Raspberry Pi BOINC Client from Project Mooninite

airbornesurfer
airbornesurfer
19 Jun 2019

CP at NUCC put these scripts together to handle communication with the BOINC server for our element14 Presents collaboration.

 

boinc.py

import subprocess

class boinc():


  # Executes boinccmd commands
  def cmd(self, command):
    try:
      command.insert(0, "boinccmd")
      p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
      return p.communicate()
    except OSError:
      print("[-] Boinccmd is not installed. Try apt-get install boinc-client")
      quit()
    except:
      print("[-] Error! '%s' failed." % (command))
      return None

  def get_tasks(self):
    return self.fss_parser(self.bcmd_rparse(self.cmd(["--get_tasks"])))

  def bcmd_rparse(self, resp):

    if resp == ('',''): # No Message, No Error. Looks like things went well.
      return True

    #fail
    # there seems to be a bug with certain boinccmd communications to boinc clients, change this to check for resp0 before returning false for the presence of resp1
    if resp[1].startswith("Operation failed: Error 2"):
      return resp[0].strip()

    mesres = {
      "can't connect to"                       : "[-] Boinccmd can't contact worker. Check BOINC client settings/process.",
      "Operation failed: read() failed"        : "[-] Boinccmd can't contact worker. BOINC client seems to be running, check remote GUI RPC settings.",
      "RPC error: Already attached to project" : "[-] Worker is already attached to project.",
      "RPC error: No such project"             : "[-] Worker is not attached to this project.",
      "RPC error: no such result"              : "[-] No such result. No such task exists?"}

    if resp[1]:
      for mr in mesres:
        if resp[1].startswith(mr):
          print(mesres[mr])
          return False
      print("Error!" + resp[1])
      return False
    return resp[0].strip() # FSS or other data



  def fss_parser(self, fss_raw):
    if fss_raw in ["", None, False]: # I did this for reasons, what they are I no longer remember
      return None
    if "======== " not in fss_raw:
      fss_data = self.fss_subparser(fss_raw)
      return fss_data

    fss_chunks = fss_raw.split("======== ")
    fss_data   = {}

    for chunk in fss_chunks:
      name = chunk.strip().split("\n")[0][0:-9]
      if name is not "":
        fss_data[name] = None

        if ") -----------" not in chunk: # This section has no subsections
          fss_data[name] = self.fss_subparser(chunk)
        else: # This section should have subsections
          fss_data[name] = []
          for chunklet in chunk.split(") -----------")[1:]:
            chunklet = chunklet.split("GUI URL:")[0] # We don't need the rest
            fss_data[name].append(self.fss_subparser(chunklet))
    return fss_data

  def fss_subparser(self, fss_chunk):
    data = {}
    for line in fss_chunk.strip().split("\n"):
      if ":" in line:
        if line.strip().endswith(":"):
          line += "N/A" # "default" value for if no value exists
        var, val  = line.strip().split(":",1)
        data[var.strip()] = val.strip()
    return data

 

start_here.sh (run as root on startup)

sudo apt-get install boinc-client
boinccmd --project_attach http://setiathome.berkeley.edu/ [your BOINC project ID]
boinccmd --project_attach http://asteroidsathome.net/boinc/ [your BOINC project ID]

 

tasks.py (to get percentage complete updates)

import boinc

bnc = boinc.boinc()


tasks  =  bnc.get_tasks()['Tasks']

for task in tasks:
  print task
  print

print

for key, value in tasks[0].iteritems():
  print '%s: %s' % (key,value)


print
print

for task in tasks:
  done_percent = task['fraction done']
  print "task %s is %s done" % (task['name'], "{0:.2%}".format(float(task['fraction done'])))

  • Sign in to reply
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2023 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • Facebook
  • Twitter
  • linkedin
  • YouTube