Python on Arduino YUN

Hello,

I'm working on a project with the Arduino YUN. It runs python 2.7.3. On the platfrom runs a webserver (with a bridge), that provides a *html file a serial communication, websocket or http conncetion. I want to implement a TCP Server, that can exchange data with WiFi, or to process incoming sensor data.

Well the problem is I got the main class, with all its commands in the self.handle():

For the TCP Server i need another class with its handles, but also all the methods from the other class.

Now can i run many python scripts on the YUN, or how to run 2 servers in one script?

See and thank you
N. Ehrhardt

The demo develop on PC deploy on Yun may give you some ideas.

And I am asking the moderator to move this to the Yun section.

...R

@N. Ehrhardt,
What are you trying to do? Not your code, not the python, your project.

Your description sounds convoluted. Your English is below average.

Please talk about your project

TIA
Jesse

Mh, I want to send data from a sensor via a Wlan module to the arduino. There it shall be saved onto sd and presented with a webinterface. The webinterface with bridge exists already. The Webserver is written with python 2.7.3

Mh, I posted this in the programming section, because the core question is about python 2.7.3
I want to implement the socket application in a main class, that also works with the Streamrequesthandler. Now my handbook does not know this class, also it is python 3... version problems.

I got angry because of this langauage, the easiest examples produce nothing but errors.

I'm trying to implement a simple socket at the moment :\ simple easy code from python.org:

Echo server program

import socket

HOST = 'localhost' # Symbolic name meaning all available interfaces
PORT = 321 # Arbitrary non-privileged port
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((HOST, PORT))
s.listen(1)
conn, addr = s.accept()
print 'Connected by', addr

while 1:
data = conn.recv(1024)
if not data: break
conn.sendall(data)
conn.close()

Well German:
Traceback (most recent call last):
File "C:/Python27/Projects/273_TCPSocketserver", line 7, in
s.bind((HOST, PORT))
File "C:\Python27\lib\socket.py", line 224, in meth
return getattr(self._sock,name)(*args)
error: [Errno 10048] Normalerweise darf jede Socketadresse (Protokoll, Netzwerkadresse oder Anschluss) nur jeweils einmal verwendet werden

My english should not be one of your matters.

N-Ehrhardt-de:
My english should not be one of your matters.

A very strange statement.

If he cannot understand you it matters.

(Having said that I could not write a question in German - not even in bad German)

...R

@N. Ehrhardt

You are trying to reinvent the wheel. There's already a solution for those task, it's called a 'web-framework'.
I recommend you using Flask, it's a well known webframework for lightweight apps in python.
On a web-framework you can easily serve webpages, listen to TCP sockets, listen to AJAX calls and more..

Here's a little gide where they install Flask on the Yun:

mart256:
I recommend you using Flask, it's a well known webframework for lightweight apps in python.

The code in the link I gave in Reply #1 includes the Python Bottle web framework

...R

Nice, bottle framework is also another lightweight one and easy to setup.

N-Ehrhardt-de:
...
I'm working on a project with the Arduino YUN. It runs python 2.7.3. On the platfrom runs a webserve
...

FYI

Openwrt Chaos Calmer RC3 ( release candidate 3)

Build in:

python 2.7.10

Python 2.7.10 released on 23 May 2015.
Python 2.7.9 released on 10 December 2014.
Python 2.7.8 released on 1 July 2014.
Python 2.7.7 released on 31 May 2014.
Python 2.7.6 released on 10 November 2013.
Python 2.7.5 released on 15 May 2013.
Python 2.7.4 released on 6 April 2013.
Python 2.7.3 released on 9 April 2012.

python 3.4.3

Python 3.4.3 released on 25 February 2015.

twisted Python networking engine
twisted-conch Twisted - Conch
twisted-lore Twisted - Lore
twisted-mail Twisted - Mail
twisted-names Twisted - Names
twisted-news Twisted - News
twisted-runner Twisted - Runner
twisted-web Twisted - Web
twisted-words Twisted - Words

Yun is base on Openwrt Attitude Adjustment.

Wait Yun update...

N-Ehrhardt-de:
Mh, I want to send data from a sensor via a Wlan module to the arduino. There it shall be saved onto sd and presented with a webinterface. The webinterface with bridge exists already. The Webserver is written with python 2.7.3

Mh, I posted this in the programming section, because the core question is about python 2.7.3
I want to implement the socket application in a main class, that also works with the Streamrequesthandler. Now my handbook does not know this class, also it is python 3... version problems.

I got angry because of this langauage, the easiest examples produce nothing but errors.

::::SNIP::::

My english should not be one of your matters.

@N-Ehrhardt-de,
thank you for your reply. Your explanation is better.
I understand you may have been upset when you wrote your original post.

I said your English was below average because many times people on the board have poor English. Your English is better than most, but your second post shows you have good English skills.

ON YOUR PROBLEM:
The library you are using is NOT for the Arudino YUN. This is a common mistake.
The Yun has it's own library.
https://www.arduino.cc/en/Reference/YunBridgeLibrary

The following informaiton will help you to understand the YUN, and fix many common problems people have when using Yun for the first time.

= [Q:] I cannot connect to My Arduino Yún. What do I do? =

First it's good to know, when Arduino Yun cannot find the AP you have set it for (like your home wifi), it has a script that puts it back into default SSID and AP mode.

Next, you may have already watched this video, but it's worth watching again. Pay extra attention to the part with the sketches.
Getting started with Arduino Yún - tutorial (6:53)

Then, read these short instructions. We (the volunteer support group) already know these steps by heart, so be familiar with the different reboot methods, and especially the 30+ second wifi reset. Also, not mentioned on that page, if you reset the Wifi/Linux part of the Yun, it will take from 2-8 minutes for the reboot. Lastly on this part, YOU MUST WAIT for the Linux portion to fully boot BEFORE YOU PRESS ANY of the REST buttons.

Lastly, before you do this make sure you backup and data you have on your Yun as it will be lost after this reset.

Resetting the processors (AR9331, WiFi, and 32U4)
http://arduino.cc/en/Guide/ArduinoYun#toc6

'''Then start over''', plug your Yun into the USB port, run this sketch, and hit the ''Wifi Reset button'' (for 5-10 seconds).
http://arduino.cc/en/Tutorial/YunSerialTerminal

The ''YunSerialTerminal'' provides a simplified console access to the Linux part of the Yun. It works via the USB port (the one that powers the Yun - the microUSB). From there you'll be able to run a few commands to give us a better idea of problems.

Also, be ready with this sketch YunWiFiStatus. This sketch will help us see the status of your home AP. The sketch prints the wifi status to the console every 5 seconds or so. This sketch might seem familiar as it was in that first video link (above).

Let us know how it goes.
Post results from the YunSerialTerminal, if you are still having problems.
Please use markup when posting results.

Jesse

arduino_markup.png

N-Ehrhardt-de:
My english should not be one of your matters.

Das Problem mit Deinem Englisch ist das es sehr schwer zu verstehen ist. Du benutzt Woerter wie aus einem Woerterbuch die aber im Zusammenhang keinen Sinn im Englischen machen, da sie eine andere Bedeutung habe koennen.

Ralf

PCWorxLA:
Das Problem mit Deinem Englisch ist das es sehr schwer zu verstehen ist. Du benutzt Woerter wie aus einem Woerterbuch die aber im Zusammenhang keinen Sinn im Englischen machen, da sie eine andere Bedeutung habe koennen.

Ralf

Please provide an English translation as this is the English section of the Forum.

...R

Robin2:
Please provide an English translation as this is the English section of the Forum.

...R

But that would not serve the intended purpose.

And I seriously hope that this doesn't mean now that all those language Nazis come out of the woodworks. When people complain about bad English wording, then there needs to be a way to clarify issues right on the spot.

Ralf

PCWorxLA:
But that would not serve the intended purpose.

And I seriously hope that this doesn't mean now that all those language Nazis come out of the woodworks. When people complain about bad English wording, then there needs to be a way to clarify issues right on the spot.

Ralf

The way is learning english properly (easier than learning arduino IMO), ask someone to translate (avoiding google translate) or posting in your language forum.

PCWorxLA:
But that would not serve the intended purpose.

How do we know what that purpose was ?

For all I know it was something very unpleasant that should not be said on this Forum ?

...R

Robin2:
How do we know what that purpose was ?

My purpose was to explain to him that he needs to realize that his attempt on communicating in English was not easy to understand...

For all I know it was something very unpleasant that should not be said on this Forum ?

...R

See above...

Ralf