What is the terminal script to run CoAP server - python

Im trying to run this CoAP server from https://github.com/Tanganelli/CoAPthon on a raspberry pi. i cant seem to find much instructions. This was one of the CoAP that my instructor wanted us to use, my instructor pretty much left us hanging with no help at all but this link.
i followed the install instructions on the github page, the only thing that wouldnt install is the section
Install instructions for CoRE Resource Directory. Mongod wouldnt install for this section so i gave up. so i dont know if this section is important or not
What are the commands for the terminal to get it running and doing something.
it says to type in to run the server coapserver.py.
cd CoAPthon
python coapserver.py
and from what it looks like its running
but nothing happens, so im not sure if its just not working or if theres just nothing there for it to do, or if there is another file i need to run with the coapserver.py.
Im very new to using CoAP and will eventually need to add a sensor to it do record temp but i want to make sure i know the server is running properly before i add that part in
any input would be great

For future individuals that might need help with this, use aioCoAP, its much easier then CoAPthon
get it from here https://aiocoap.readthedocs.io/en/latest/installation.htmlg
all you need to do is mess with three files labeled server.py, clientPUT.py and clientGET.py
Add resources and classes for sensors and what not to server.py
ClientPUT.py is where you would add your code for the sensors or whatever you need.
ClinetGET.py you alter the uri
run it by type in the command in the terminal (go to directory first that has the server) type in python server.py
in another terminal do the same thing but instead run python clientPUT.py
and the server should be running
then all you need is a client for the get request. If you were like me and needed to use Copper go here to install it for chrome https://github.com/mkovatsc/Copper4Cr

Related

Executing a curl command on the client side

Let us say that I am running on a Debian machine a server with sudo python3 -m http.server. Are there possibilities to execute some curl command on the client-side if he opens the website?
My idea is to provide an installation page for my program, so if the user opens it (http://127.0.0.1/install), the commands would be automatically executed in the background. I am aware that there are security reasons why this shouldn't be possible, but let's say the user is okay with it. :)
I have found online something about cgi python scripts, but I never found any example to do what I want and that is why I am not really sure if it is the right thing or not.

How do I set up Jupyter notebook on a linux server (RHEL7) for my team to use via Chrome browser?

I am leading a team of analysts and want to introduce them to Jupyter Notebook as a window into Python programming.
We have Anaconda downloaded and installed on our Linux server. I've asked our IT to help set it up to run on Google Chrome and they have been able to only provide the following steps:
source /R_Data/anaconda3/etc/profile.d/conda.sh
this kicks off Anaconda on the server, must run in PUTTY. We stored the installation in the same location as RStudio hence the R_Data in the filepath.
/R_Data/anaconda3/bin/jupyter-notebook --ip 0.0.0.0 --port 8889
This sets up the port 8889 with a token generated each time from scratch. We then need to grab the token id and paste into Chrome with the full URL per step 3
http://localhost:8889/?token=ea97e502a7f45d....
When I paste this in Chrome it loads Jupyter.
While this gets the job done it seems less than ideal for an entire team of analysts to have to do this each time. We also have RStudio installed on the same server but that simply opens from Chrome using a URL since I assume it is always running in the background. Jupyter and Anaconda seem to only run once they are kicked off first in PUTTY and I would like a way to bypass those steps.
I am familiar with the Jupyter config file however my limited understanding as a non-developer tells me it applies only to each user and cannot be applied to all users simultaneously (i.e. as a root user on the server or something to that effect).
I am hoping someone here might point me in the right direction. I should also point out that as a Redhat user I can't follow instructions based in Ubuntu since that syntax seems different.
Many thanks for the help.
Yoni
A convenient way is to run jupyter notebook --no-browser --port=12345 on your server while connecting through the ssh tunel as ssh -N -f -L 12345:localhost:12345 myserveralias. Now jupyter is on your 12345 localhost. Things like AutoSSH or Keep Alive will help with an erratic network, however, take security into account.

How to install and run python script on Microsoft server

Guys and ladies. I am new to programming. I have written some script.It just checks whether some data is correct or not. I want that script to run 24*7 on Microsoft server at job (not on my PC). Please let me know how to do that.
thanks in advance
Aside from general server set-up, you will just need to download Python like you would on any server.
As for the running, something like python yourScript.py would work fine. In order to run it 24/7, you need to put your entire script in a while(True): loop so that it never stops running. Note that you should also include some DECENT error handling in the event on an issue so that it doesn't just crash.

vi command returns error format data?

I'm using python 2.7 and paramiko library. client app running on window sends ssh commands to server app running on linux.
when I send vi command, I get the response
<-[0m<-[24;2H<-[K<-[24;1H<-[1m~<-[0m<-[25;2H....
I don't know what these characters mean and how I process it. I'm struggling for hours, please help me.
Reviewing my SO activity this week, saw this opportunity to whore for rep:
Those look like ANSI/VT100 terminal control codes, which suggests that something which thinks it is attached to a terminal is sending them but they are being received by something which doesn't know what to do with them.
Now you can Google for 'VT100 control codes' and learn what you want.

How can I create an local webserver for my python scripts?

I'm looking to use a local webserver to run a series of python scripts for the user. For various unavoidable reasons, the python script must run locally, not on a server. As a result, I'll be using HTML+browser as the UI, which I'm comfortable with, for the front end.
I've been looking, therefore, for a lightweight web server that can execute python scripts, sitting in the background on a machine, ideally as a Windows service. Security and extensibility are not high priorities as it's all running internally on a small network.
Should I run a native python webserver as a Windows service (in which case, how)? Or is it just as easy to install Apache onto the user's machine and run as CGI? Since this is all local, performance is not an issue either.
Or am I missing something obvious?
Don't waste a lot of time creating Windows service.
Don't waste a lot of time on Windows Apache.
Just make a Python service that responds to HTTP requests.
Look at https://docs.python.org/2/library/basehttpserver.html
https://docs.python.org/3/library/http.server.html for version 3
Python offers an HTTP server that you can extend with your server-side methods.
Look at http://docs.python.org/library/wsgiref.html
Python offers a WSGI reference implementation that makes your server easy and standards-compliant.
Also http://fragments.turtlemeat.com/pythonwebserver.php
"I'm trying to avoid making the user run python stuff from the command prompt."
I don't see how clicking a web page is any different from clicking desktop icons.
Starting a web server based on Python is relatively easy, once you have the web server. First, build the server. Later, you can make sure the server starts. Let's look at some ways.
Your user can't use a random browser to open your local page. They need a bookmark to launch "localhost:8000/myspecialserverinsteadofthedestop/" That bookmark can be a .BAT file that (1) runs the server, (2) runs firefox with the proper initial URL.
You can put the server in the user's start-this menu.
You can make your Python program a windows "service".
Best way is to make your own local server by using command prompt.
Make a new folder say Project
Make a new folder inside project & name it as "cgi-bin"(without quotes)
Paste your .py file inside the cgi-bin folder
Open cmd and change to the directory from which you want to run the server and type "python -m CGIHTTPServer"(without quotes)
Minimize the cmd window & open your browser and type "localhost:8000/cgi-bin/yourpythonfilename.py"(without quotes).
The wasiest step would be navigate to folder where your files are located and running http.server module
cd /yourapp
python3 -m http.server
the you should see something like this in console
Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ...
Running a native python webserver as a windows service should be a no brainer. Check out the documentation for writing windows services (win32api, ActiveState python) in python and also the documentation for subclassing BaseHttpServer and SimpleHttpServer.
BTW: I had a similar question on stackoverflow: How to stop BaseHTTPServer.serve_forever() in a BaseHTTPRequestHandler subclass?
Basically, you subclass BaseHTTPServer (you have to anyway...) and then... but just read the accepted answer - it set me on the right track!

Categories

Resources