How to create a Arduino/Raspberry pi api? - php

I always want to create an API which lets me send value over the internet to an specific Arduino board or raspberry, I know that I can do it with a third party Server like>
https://www.teleduino.org/
or https://www.yaler.net/ or if I use Raspberry I can install it Android and send data through GCM. But I don't want to use any other server, I already have a PHP hosting.
I think that I need to open a XMPP port or something to call directly the Ethernet shield or the the raspberry pi IP.
Will I need a static IP.
Any suggestions?

You want to write you own PROTOCOL, it can be based or use other protocol.
If you have complete access to server, my suggestion is to use TCP Socket direcly (Client class on arduino with write e read, like using the Serial), if you can't then you have to "tunnel" your PROTOCOL over an accepted protocol on the server. If it has php then the protocol il HTTP, witch is based on TCP. see http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Example_session

Related

How to send commands to gps tracker with php

I'm trying to develop php based tracking software for my gps tracker gps107.
My tracker has GPRS and I have successfully associated my tracker with open source tracking software "Traccar" which is written in java and located in my server.
But now I want to develop my own custom software for my needs in php.
I also have the protocol manual where I can see available commands and their responses.
example command for locating:
server -> device
**,imei:359586018966098,100
device -> server imei:353451044508750,001,0809231929,,F,055403.000,A,2233.1870,N,11354.3067,E,0.00,,;
How can I send these commands with php ?
The communication between server and a device is made with UDP or TCP protocol. To make this type of a connection with PHP you have to create PHP socket server. Then you assign server IP and port to your device, and the device will connect to the server as a client. After that you can receive and send commands.
PHP Doumentation about sockets: http://php.net/manual/en/book.sockets.php
Excample socket server: http://devzone.zend.com/209/writing-socket-servers-in-php/

Create telnet client that uses server's TCP/IP stack instead of users?

If I used something server side like PHP inconjuction with some web wizardry for the interface, would it be possible to create a web-based telnet client that uses the server's TCP/IP stack instead of the users?
I've seen a PHP based MUD client, but it uses Websockets or Flash based on the user's machine. I'm looking to see if it would be possible to make use of the server's connection to generate a telnet session.
At work, telnet is blocked outbound. I would login to a web server that had this little web app running, and through that web server, I could utilize it's ability to telnet to another server?
Yes, but if it would be using HTTP, which is stateless, you would have a lot of overhead (like logging in each request).
Since it is telnet though, its fairly simple. Check out fsockopen. There's a few telnet examples in the comment section.

Making the web server as a relay between two sides

I want to control a robot from the web, the robot is connected to Android device. The operation will be as the following :
a web application written using JavaScript and HTML runs on desktop computer which takes the keyboard input from the user and send them to the android device connected to the robot.
the android device receive the commands and then send them to Arduino board which used to control the robot.
But how should I deliver the data to the Android device which doesn't has a static IP address?
I have two approaches to solve that :
the JavaScript application sends the keyboard input to a web server runs PHP and MySQL , then the php application store the data on the MySQL database. An application runs on Android connected to that web server and extract the data from the MySQL database.
the JavaScript sends the data to the web server. The android application connected to the web server receives the data directly so the web server is just used as a relay.
The first approach is easy to do but its slow , so my question is...
How to implement the second approach and which web technologies should I use to implement it? And how to make the web server works as relay between two sides?
PS : I am planning to use 000webhost.com as web server. so I will not use my own server
You can either have your Android application poll the webserver for outstanding commands. This is a little inefficient in terms of data usage, but if you're on an unlimited 3G plan / wi-fi, you could live with it. It will be very easy to implement.
Alternatively, set up a TCP server on your server, and have your Android application open a socket connection with the server. This way, your web application can send commands to the server which will immediately stream them to the Android device. It will be slightly harder to implement, but will be more efficient and robust if done right.
PS - Most shared servers don't allow you to open a TCP server on your host so you might be forced to go with the first option.
PPS - I wasn't aware of Google Cloud Messaging. It seems to be a good solution for you what you're attempting to achieve. You should have a look into it.

PHP script that enables client communication with custom hardware

We have a wireless device (WIFI enabled) that calls a PHP script to enter data into MySQL db. Am trying to find a way to see if the server (through PHP script) can "connect" to the client device (has a microcontroller but doesn't have an OS or display) and pass some data.
The client is a electronic board connected to a gate and the server needs to tell the device to open the gate. Seems to be pretty straight forward but am new to this.
If the client is configured to listen on a specific port, you can open a socket connection to it from the server (using fsockopen()).
You'll need to configure the client though, which I have no idea how to do because your client is nothing standard.

Send udp packet on LAN from web browser

I have built a simple TAPI app that will run on a machine on the LAN that connects to the office PBX, it allows me to receive dial, answer, hangup etc commands (which I was planning on receiving via a udp packet). I did this with the intention to integrate the office CRM system to the phone system.
Having done this and testing using a simple python app to send the udp packets I find myself wondering how to send the udp packets to this app given that the CRM system is a web app written in php/javascript.
We use Firefox in the office and so I was going to start with a Firefox extension, but I thought I would ask and see if anyone has any experience on sending udp packets over a lan from a browser using java or flash or from a browser extension/plugin.
Or is there a better cross browser way to send commands to an app on a network pc when the web app is hosted online?
Maybe in the CRM you could use javascript and JSONP to make a request to a local HTTP server, and that server could then send the UDP packets instead.

Categories