Go Down

Topic: UDP supported? (Read 24738 times) previous topic - next topic

sonnyyu


esbjerg

On it now!
Thank you so much for taking the time to help me!

esbjerg

#32
Mar 25, 2014, 05:22 pm Last Edit: Mar 25, 2014, 05:25 pm by esbjerg Reason: 1
Okay, so nothing to reset is coming up on the arduino.local page. I used my computer to put the file on the SD card.
The SD card is called SD and I put the file in the root folder

EDIT: Tried using terminal too, same message as before, no such file or directory

sonnyyu

#33
Mar 25, 2014, 05:41 pm Last Edit: Mar 25, 2014, 05:47 pm by sonnyyu Reason: 1
Re: Problem with microSD

http://forum.arduino.cc/index.php?topic=222069.msg1614584#msg1614584

PC is no needed for helping create file or directory at linino.

esbjerg

Next issue ,followed the steps in that link, I can't  see the sd coming up with  fdisk -l.
Just keep asking if I specified it correctly.

esbjerg

Looking at this link I think it may be faluty.

http://forum.arduino.cc/index.php?topic=201829.0

Going to try this all with a flash drive... I read they mount in similar ways, so thinking that should work the same?

esbjerg

Tried with the USB flash drive and I can now write the lines of code! (success)
but when I try and run it I now get permission denied! (aww)

Any ideas?

sonnyyu


esbjerg

Awesome, I can receive the G over on another laptop running Max, woo.
Now I'm trying to send 4 analogue pins over it (and ideally a couple of digital things, but not essential at the moment). Looking into bridge etc, but I can't work out how to get it from the arduino sketch into the python sketch (then onto Max).
I'm guessing that I'll need to change MESSAGE into something? Again, thankyou!

esbjerg

#39
Mar 26, 2014, 11:24 pm Last Edit: Mar 27, 2014, 12:41 am by esbjerg Reason: 1
Sorry to be that guy, but I feel like I'm so close to having it working!!

To try and get serial input to be posted straight out of the python sketch, it now looks like this:

Code: [Select]
#!/usr/bin/python
import socket
import serial

ser = serial.Serial('/dev/ttyATH0', 9600)

while ser.readline() != 'A':
#   do nothing
   pass

UDP_IP = "192.168.1.242"   #Max IP address
UDP_PORT = 8888
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # UDP

data_raw = read(8) #read 8 bytes
sock.sendto(bytes(data_raw), (UDP_IP, UDP_PORT)) #sends the byte
#recvmsg=sock.recv(1024) #read response
#print recvmsg
sock.close()
               


Was getting an indent error (now fixed), but now it seems to run perfectly, but doesn't put anything out into udp...

Thanks again..

richard47

I have a general question about developing on the Yun using Python.

If my Python code has an error in it then how can I see the error messages?

I can test the Python code in Python on my iMac but there appear to be differences in the syntax so I could still get an error when the code is run on the Yun.

sonnyyu

#41
Mar 29, 2014, 04:35 pm Last Edit: Mar 29, 2014, 04:50 pm by sonnyyu Reason: 1
Yun's python version:

Code: [Select]
python  -V

Code: [Select]
Python 2.7.3

My iMac's python version:

Code: [Select]
python  -V

Code: [Select]
Python 2.7.5

The  differences in the syntax should be very minimum if it exists.

Python's community is vast:

https://www.python.org/community/

richard47

I am running v3.4 on my iMac. Yesterday I tried going back to v2.7 and for some reason I couldn't get it to run any of my Python code.

Is there any way to see errors in the Python code on the Yun?

richard47


At Yun:

Code: [Select]
nano /mnt/sda1/udp.py

Code: [Select]
#!/usr/bin/python
import socket
UDP_IP = "192.168.0.230"   #Uno IP address
UDP_PORT = 8888
MESSAGE = "G"
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # UDP
sock.sendto(bytes(MESSAGE), (UDP_IP, UDP_PORT))
recvmsg=sock.recv(1024)
print recvmsg
sock.close()


Code: [Select]
/mnt/sda1/udp.py

make sure return value from nano.

Code: [Select]
#!/usr/bin/python
import socket
import sys 
sys.path.insert(0, '/usr/lib/python2.7/bridge/')
from bridgeclient import BridgeClient as bridgeclient
UDP_IP = "192.168.0.230"   #Uno IP address
UDP_PORT = 8888
MESSAGE = "G"
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # UDP
sock.sendto(bytes(MESSAGE), (UDP_IP, UDP_PORT))
recvmsg=sock.recv(1024)
#print recvmsg
sock.close()
bc = bridgeclient()                         
bc.put('to_arduino',recvmsg)


sannyyu: I am using your code shown above to control my WiFi lights successfully but now I would like to be able to receive UDP messages from my iPhone/iMac and to send a reply. The messages from the iPhone/iMac can be sent at any time.
I have added the following code to receive UDP messages from my iPhone and to send a reply. However, the Python code hangs and I never see the output from the statement  - print("After dataFromClient"). If I send a UDP message from my iPhone then the print is executed.

I would like the code to continue processing if no UDP data has been received. I am testing this on my iMac running Python v3.4 and sending UDP test messages from my iPhone.

Code: [Select]
server_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
server_socket.bind(('', 6666))
print ("UDPServer listening on port 6666")

while True:
  dataFromClient, address = server_socket.recvfrom(256)
  print ("Received %d bytes: '%s'" % (len(dataFromClient), dataFromClient))
  if (dataFromClient == b'g'):
    msg = 'G,' + str(lightReading)
    server_socket.sendto(bytes(msg, 'utf-8'), address)
  elif (dataFromClient == b'n'):
    msg = 'N,' + str(nSchedules) + str(lightReading)
    server_socket.sendto(bytes(msg, 'utf-8'), address)
  else:
    print ("( " ,address[0], " " , address[1] , " ) said : ", dataFromClient)

  print("After dataFromClient")

sonnyyu

Quote
sannyyu: I am using your code shown above to control my WiFi lights successfully but now I would like to be able to receive UDP messages from my iPhone/iMac and to send a reply.


It is sonnyyu.  :smiley-eek-blue:

I never code python on Mac or Windows but Linux:

Code: [Select]
#!/usr/bin/python3
....


It will run at 3.X

Code: [Select]
#!/usr/bin/python
...


It will run at 2.X

I believe that Python 2 and Python 3 could coexist peacefully at Macintosh as well.



Go Up