The problem is when i'm runing this scrip from linux shell everything works fine, but when i'm runing the same script with arduino sketch i see just 2 first "print" commands of the script insted of 3 prints.
It may not be finding the file to open, and stopping the script because of it. Besides the first two lines printing out, are you getting any error messages?
When you run it from the Linux shell, I assume you are running it from the directory where the file exists. It finds the file and runs properly.
When you run it from the sketch, it's probably not running from the same directory, so it can't find the file.
Perhaps you can change the open command to include the full path name to the file?
Good catch. Although in this case it may not make a huge difference, since he's explicitly calling Python to process the script.
The hash-bang on the first line is there to tell the command line interpreter which program it should call to run the script. But that's really only important when the script file is set to be executable and you're running the script by just typing its name.
vicmerlis: the solution was -> copy addDT4ToStack.txt file to /usr/lib/python2.7/bridge directory :\
That doesn't sound like a very good solution.
I wonder why the absolute path and CD didn't work? Either of those would be much more appropriate.
/mnt/sd/ is a logical link that is created when an SD card with an /arduino/ folder at the root is found. The card is actually at /mnt/sda1/. Clutching at straws, maybe Python isn't liking the link to the disk? I wonder how the file open or cd would work using the physical path /mnt/sda1/arduino/...?
ShapeShifter:
That doesn't sound like a very good solution.
I wonder why the absolute path and CD didn't work? Either of those would be much more appropriate.
/mnt/sd/ is a logical link that is created when an SD card with an /arduino/ folder at the root is found. The card is actually at /mnt/sda1/. Clutching at straws, maybe Python isn't liking the link to the disk? I wonder how the file open or cd would work using the physical path /mnt/sda1/arduino/...?
jessemonroy650: @vicmerlis,
I did something evil. I ran your code. It says, "NameError: name 'sys' is not defined"
errr.... Where is the rest of your code?
Jesse
#!/usr/bin/python
import socket
import sys
import os
UDP_IP = sys.argv[1]
UDP_PORT = int(sys.argv[2])
NUM_OF_ITTER = int(sys.argv[3])
try:
file = open('/mnt/sda1/arduino/addDT4ToStack.txt','r')
except IOError as e:
print 'cannot open ({0}): {1}'.format(e.errno, e.strerror)
temp = file.read()
file.close()
MESSAGE = temp.split(';')
for i in range(0,NUM_OF_ITTER):
print "DT4 number " + str(i+1) + " was sent"
temp = MESSAGE[i].split(',')
temp = map(int, temp)
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # UDP
sock.sendto(bytearray(temp), (UDP_IP, UDP_PORT))
sock.close()