BBBlack hangs in some hours!

I have a python script running on a raring BBBLack ubuntu image that has wiFi working flawlessly, but while using the python script as follows I’m see that the script runs but the Request Log on the xively dashboard isn’t receiving anything?!

Is there a frequency limit for which I can update the feeds?

Or is it my App? Which I think is running and not going down.

here’s the code:

`

#!/usr/bin/env python

import os
import xively
import subprocess
import time
import datetime
import requests
import serial
import re
import string
from select import select

#OS variables and other settings for UART transfer
os.system("sudo chmod 777 -R  /sys/devices/bone_capemgr.8/slots")

os.system("sudo echo ttyO1_armhf.com > /sys/devices/bone_capemgr.8/slots")

serial = serial.Serial("/dev/ttyO1", baudrate=9600)

resp = ""
inData = ['']*14
started = False
ended = False
check_point = 0
check_point_listener = 0

# extract feed_id and api_key from environment variables
FEED_ID = "34534"
API_KEY = "blahhblahh"
DEBUG =   "DEBUG" or false
DEBUG_listener = "DEBUG" or false

# initialize api client
api = xively.XivelyAPIClient(API_KEY)

# function to return a datastream object. This either creates a new datastream,
# or returns an existing one
def get_datastream(feed):
  try:
    datastream = feed.datastreams.get("Lock_Controller")
    if DEBUG:
      print "Found existing datastream"
    return datastream
  except:
    if DEBUG:
      print "Creating new datastream"
    datastream = feed.datastreams.create("Lock_Controller", tags="ON/OFF")
    return datastream

# function to return a datastream object. This either creates a new datastream,
# or returns an existing one
def get_datastream_listener(feed):
  try:
    datastream_listener = feed.datastreams.get("load_avg")
    if DEBUG:
      print "Found existing datastream"
    return datastream_listener
  except:
    if DEBUG:
      print "Creating new datastream"
    datastream_listener = feed.datastreams.create("load_avg", tags="load_01")
    return datastream_listener

# main program entry point - runs continuously updating our datastream with the
def run():
  print "Script initiation"

  #Initializing one channel
  feed = api.feeds.get(FEED_ID)
  datastream = get_datastream(feed)
  datastream.max_value = None
  datastream.min_value = None
  #Initializing one channel
  feed_listener = api.feeds.get(FEED_ID)
  datastream_listener = get_datastream_listener(feed_listener)
  datastream_listener.max_value = None
  datastream_listener.min_value = None

  while True:
     while serial.inWaiting() > 0:
           inChar = serial.read() # Read a character
           if inChar =='<': # not sure what to put in if statement to run until end 
              global started
              started = True
              global ended
              ended = False
              index = 0
           elif inChar =='>':
              global ended
              ended = True            
           if started == True:
              inData[index] = inChar # Store it
              index = index + 1      # Increment where to write next
              #inData[index] = '\0'   # Null terminate the string     
           if ended == True:
              global ended
              ended = False
              index = 0
              Data = inData #values of acclerometer like "545X" etc enter and stored in Data 
              print (Data)
              values = "".join(str(v) for v in Data)    
              print (values)       
              strData = string.replace(values, "<", "")
              strData = string.replace(strData, ">", "")
              strData = string.replace(strData, " ", "")
              strData = string.replace(strData, "\0", "")
              print (strData)
              if strData[0] == 's' and strData[1] == 't':
                 print "Nishant Here"
                 strData = string.replace(strData, "st", "")
                 strData = string.replace(strData, "\0", "")
                 strData = string.replace(strData, " ", "")
                 print strData
                 if strData == '1':
                    print "This is arrived at 1"   
                    global check_point_listener              
                    datastream_listener.current_value = str(check_point_listener) + "h"
                    datastream_listener.update()
                    #serial.write("<v0" + str(check_point) + ">") #serial write value 
                    time.sleep(1)
                    datastream_listener.current_value = 0
                    datastream_listener.update()
                 elif strData == '0':
                    print "This is arrived at 0"   
                    global check_point_listener                
                    datastream_listener.current_value = str(check_point_listener) + "L"
                    datastream_listener.update()                  
                    time.sleep(1)
                    datastream_listener.current_value = 0
                    datastream_listener.update()
     if DEBUG:
               print "Updating Xively feed with value: %s"   
               global check_point
               check_point = 0
               datastream = get_datastream(feed)
               global check_point
               check_point = datastream.current_value
               print "AAGYa: %s" % check_point
               for x in range(1,61):
                   #print x
                   checking = int(check_point)
                   if x == checking:
                       print "Got it"
                       serial.write("<ch" + str(x) + ">")
                       datastream.current_value = 0
                       datastream.update()
     if DEBUG_listener:
               print "Query stuff: %s"   
               global check_point_listener
               check_point_listener = 0
               datastream_listener = get_datastream_listener(feed_listener)
               global check_point_listener
               check_point_listener = datastream_listener.current_value
               print "AAGYa: %s" % check_point_listener
               check_point_listener = string.replace(check_point_listener, "L", "")
               check_point_listener = string.replace(check_point_listener, "h", "")
               for x in range(1,61):
                   #print x
                   checking = int(check_point_listener)
                   if x == checking:
                       print "Got it Query"
                       serial.write("<Q" + str(x) + ">")             

run()

`

Running Ubuntu raring from Robert C Nelson 13.04 version!

I would recommend you setup the tty port in startup scripts or at least delay after setup.

This very same code is turned into a executable using chmod +x and then provided full 777 privileges and made a start up script using Upstart.
I think this is fine here, whats say?

Thanks & Regards,
Nishant

You need to give cape manager time to setup tty after echo command before talking to device. Shouldn’t need sudo either if done right. This is working great in my pentesting devices using xbee modems on ttyo2.

Ok I understand your point But if TTy isn’t configured correctly from the very beginning how could it then function at all? I mean in my case all the UART hardware function goes perfectly well but after sometime like an hour or so the script goes down.

Either your script or device. I run my stuff for days w/o problems.

Philip,

Okay can I have your code or what exactly you are doing(If can provide code then it would be the best for me)

thanks!

Or atleast detailed way that how you are doing it?

If your not using any capes, give the v3.12.x branch a try. .(specially for
usb related lockups..)

wget http://rcn-ee.net/deb/raring-armhf/v3.12.0-bone8/install-me.sh
sudo /bin/bash install-me.sh

Regards,

Hello Mr.Robert

Glad to see the image maker here>>
I’m not using any capes!
also wgetting that branch will make drastic changes? You see my concern is that I already spent a lot of time installing individual needy items from the very big pool so I don’t want to install them again, will this change things drastically?

It just installs the 3.12.x based kernel..

You can see the details of the install-me.sh script here:

https://github.com/rcn-ee/farm/blob/master/install-me-template.sh

Including where it backs up your existing kernel files..

https://github.com/rcn-ee/farm/blob/master/install-me-template.sh#L136

Regards,

Give Robert’s 3.12 kernel a try. As for my code, download the MeshDeck from http://sf.net/projects/thedeck and look at install script.

Ok so installing that kernel lets all other things remain the same? Like the python framework. Eclipse ide all those don’t get effected?

Thanks!

Thanks & Regards,
Nishant

Thanks philip

Hi Philip and Robert,

So I have tested the BeagleBone removing any scripts that may clash and cause the OS env. to restart and I have my BBBlack running all the night till present its still on while I’m writing this email, I checked this with “uptime” command ,so Now it seems to be a problem with upstarting of these py scripts, So here the following I give you my upstart code to respawn the py script in the even of any crash!

Start LINUX UART

Did you upgrade to 3.12 as well?

No was checking that is the problem because of script or else then after it now it seems it was python script.
Is there any anomaly in my upstart you see I want to restart the script when it dies unexpectedly.

Thanks & Regards,
Nishant

I’m not using upstart. I’m putting code in rc.local, etc. directly. It could be a problem with permissions or the timing of when your script gets executed.

Hey Philip

I gave full permissions to the py script. That’s 777 just to be sure that such problems don’t play with me.
But I think I can’t do anything about the timing as I won’t know about which script is colliding.

Also when I run script sometimes when it dies I get a sort of http error may be capturing it solves the problem. Still I just want to make sure that no matter what uncaptured etc error comes it just restarts the py script on fail because I don’t need to retain it.

Can you tell me the what are the steps you are following to restart your script.

Thanks & Regards,
Nishant