XBee Wifi send and receive data from web
eagletalontim
Posts: 1,399
As the title states, I am attempting to send data to my server and receive data as well. My first step I want to accomplish is receiving data from the web.
I have already set my router up and set my XBee in transparent mode. I am not really sure where to start On my remote server, I have written a PHP script that sends text to the specified IP address and port. I know this code works as it works on my spinneret. I have since changed the router to direct the same traffic to my XBee Module on a battery powered board.
The Xbee is connecting to the network as I can ping it. That is about as far as I have gotten. Any help is appreciated!
Processor I am using is the Prop.
I have already set my router up and set my XBee in transparent mode. I am not really sure where to start On my remote server, I have written a PHP script that sends text to the specified IP address and port. I know this code works as it works on my spinneret. I have since changed the router to direct the same traffic to my XBee Module on a battery powered board.
The Xbee is connecting to the network as I can ping it. That is about as far as I have gotten. Any help is appreciated!
Processor I am using is the Prop.
Comments
'
What do you want to display the data on?
EDIT *
My plans are to be able to read the data that is calculated from my solar panel setup and also to move the panels / park them via my phone or standard web browser. All I need to do is send 1 letter or number from the browser to the module to activate each function (Move up, down, left, right, or Park). Data sent from the circuit is not necessary, but would be handy.
'
I Posted some stuff back in the day on WiFi in this forum. Mostly for the RN171-174 but some for the XBee 802.11. I'll do a search and see if I can find it.
'
The stuff above is for the RN171/174 but should be of help with your project.
'
Do you have X-CTU installed on you pc? This is the USB interface from the XBee.
I found this and maybe it will help? This is kind of similar to what I am trying to accomplish. : http://forum.arduino.cc/index.php?topic=252543.0
It is late and I need sleep. Will attack this again when I wake up.
'
For those that aren't sure how to do this. Press ALT-Print screen "(Alt)-(PrtScr) on my keyboard". Next open up "Paint" and click edit, then paste. Edit the file, give it a name and save it as a jpeg.
Using Parallax Xbee USB module to communicate / program XBee S6B wifi module.
Newest version of XCTU V6.1.2
Remote shared hosting Server port 2616 is open as TCP/UDP. Opened it for testing. Maybe I can just use port 80?
Router set to forward requests of port 236 to port 2616 of IP address 192.168.1.123
On my remote server, I have logged in through SSH and run "nc -l 2616" then run Telnet from my PC to communicate with that port. It worked perfectly.
I am able to ping 192.168.1.123 on my home network. This is about as far as I have gotten. I cannot seem to get the XBee module to communicate with my web server. Any output of the Xbee, I would think, would be sent to port 2616 of my server and it should have been displayed on the Putty screen when running the NC command.
'
You can ping a device that does not have the passphrase.
Edit * The xbee also shows up in the attached device list of the router. I would think this means it is connected.
'
I would stay clear of port 80. That was the hacker highway back in the day. Fire walls will start blocking any communications! This could be your internet provider looking out for you.
'
Have you tried to talk to the XBee from your web sever?
Maybe I am going about this the wrong way... I have been trying to either use telnet to connect directly to the Xbee Module or have tried sending data through the XCTU console and catch it through the server "NC" command. Telnet does not connect and I can't see the data going anywhere.
So, now that I have it working on the USB board, I need to get it to work with the Prop. I found the Xbee_Object.spin on the forums and will see if I can get it to send data and receive data from the socket.
'
With telnet you need to use the little "o" to open the device. " o 198.168.1.123 2616", just in case you forgot.
'
Post a little bit of your code and trouble shooting when you get it all working.
That is port 2616 in HEX, or decimal 9750 in pretty much everything else. Have a look at the following links:
http://www.savagecircuits.com/showthread.php?662-XBee-Wi-Fi-Setup-X-CTU (setting up the XBee Wi-Fi for an existing wireless network).
http://www.savagecircuits.com/content.php?201-XBee-Wi-Fi-via-WAN-IP (Demonstration of sending packets over the internet from CA to Belgium)
I have attached my project to show my code, but testing it would probably be pretty difficult without the same circuit setup I have.
The problem I am having is the move_EW_flag and move_UD_flag not working correctly 100% of the time. I believe this problem lies somewhere in the controlMovement section or ProcessData section. What is happening is I press "RIGHT", "STOP", or "LEFT" on my HTML / PHP script and it sends text to the socket server which the XBee receives and sends it to the Prop for parsing. This is done in the ProcessData section. This appears to work correctly as the "last_data" variable is displayed in the PST which shows the data was received correctly even with it glitches. Since controlMovement is running in it's own COG, I set flags in the ProcessData section which should be picked up in the controlMovement section and processed accordingly. This works most of the time, but sometimes it does not....even when the "last_data" shows correct information and the returned string to the socket server is correct according to the command that should have been run.
For example : Flow process =
1: Click "RIGHT" on HTML form
2: String "Received:COMMAND:2:END" gets sent to socket server
3: Socket Server echos data to XBee
4: XBee receives data and the PROP receives then processes it through the PUB ProcessData.
5: If the string contains "COMMAND:", the next characters are stored as the "command" variable in the Prop.
6: Since "RIGHT" is command 2, case #2 is selected and the flag "move_EW_flag" is set to 2.
7: The PROP sends data to the XBee to send to the socket verifying data was received successfully. In this case "Moving Right.".
8: The controlMovement COG should pick up the change to the flag "move_EW_flag" and process the change (Right here is where it fails 50% of the time)
Hope this is not too confusing!
From what I have read in researching this packet loss issue is to send and receive something other than "strings" like I am now : "RX:CMD:3:#". So in researching more, I can use the PHP function "unpack" to convert each character to it's ascii code and send it to my socket which I am doing now :
What I am trying to do now is convert this on the Prop back to a string.
Here is my receiving code on the Prop as of right now :
This code properly receives data from the socket and I have not found any missing packets yet.
Now for the sending to the server is where most of the glitches happen. I use the xb.str(string("Something", 13)) method but it seems to be kind of glitchy. If I put that line of code in a repeat loop and a 1 second pause between each send, the data received on the socket will vary (Viewing with Telnet). It will either be missing a letter, or only 1/2 the string will be send / received. Any ideas?
I have not experienced any packet loss, even when using UDP which does not provide any acknowledgement that the packet made it to the destination. In the demo below you can see how many packets I sent from California to Belgium with zero packet loss.
http://www.savagecircuits.com/content.php?201-XBee-Wi-Fi-via-WAN-IP
There has to be something else going on or you have a very noisy environment/connection.
Can i take a look at the PHP code ur using?
server.php : run as a cron. Server runs this script every minute. If socket is still alive, the second request to run socket server fails and first continues to run.
index.html : Front user interface. Could have used better coding, but I just threw this together.
actions.php : Generates the connection to the socket and puts requested text to the socket server to be echoed to all clients. Called by Ajax / jQuery.
Attached is my SPIN
Nothing else connected to those pins. Resistors would not typically be used on the serial I/O unless you are using an open baud mode (which I am not). And while it is a direct connection, you can be sure those packets are making many hops between here and Belgium. I hadn't realized you were going through a server.
You can connect directly on the specified port. But over the internet your target IP becomes the WAN address of the remote and the router on that end is responsible for packet forwarding to the device inside. When the remote XBee replies the packets are returned to the origin without having to be port forwarded.
On a similar note I am working on a remote Telepresence Robot using an RB5X shell with a Propeller inside. It will be able to be controlled over the internet via an Android app and display video on a web page interface to the operator. This will be using the XBee Wi-Fi module.