OpenWrt Forum Archive

Topic: WR703N Arduino HTTP Client Get and Post Requests

The content of this topic has been archived on 19 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Im new on OpenWRT. I want to use the Arduino and WR703N as a wireless client. So that, I need to send "HTTP Get or Post requests" to my web server from Arduino over WR703N WiFi. I will insert sensor data to database table. Schematic is belown:

Sensor->Arduino->WR703N->WiFi >>>>>>>>>> WiFi->Web Server (JSP, PHP, ASP or any CGI )->Database

Of course, this is quite possible, but as it completely application-specific, you are on your own...

The idea is to write a firmware on the Arduino board to monitor the sensors, that communicates over UART (plain or VCOM over USB) with another piece of software running on the TL-WR703N that basically monitors the Arduino board output and forward it to the server by sending HTTP get/post requests. The CGI on the server then have to parse the request and do whatever is required to store the values within the database.

The software on the TL-WR703N can be a shell/Lua/Python script or a dedicated binary executable.

The transport over USB vs. plain UART, or Wifi vs. Ethernet doesn't add anything to the problem.

I would leave out the arduino and connect the sensor more or less directly to the WR703, or what can the Arduino that you can't achieve with I2C/SPI devices?

MBS wrote:

I would leave out the arduino and connect the sensor more or less directly to the WR703, or what can the Arduino that you can't achieve with I2C/SPI devices?

Real-time motor shaft position quadrature decoding wink

Besides real-time issues, the OP may have other good reasons to use an Arduino board: existing code for decoding the sensor output, 5V logic levels to deal with...

But if the sensor is just a slow I2C one, I agree that it can also be done directly with the WR703N.

SPI is more tricky though, since you will have to share the SPI bus with the onboard SPI Flash and free an additional chip select signal...

Squonk wrote:

Of course, this is quite possible, but as it completely application-specific, you are on your own...

The idea is to write a firmware on the Arduino board to monitor the sensors, that communicates over UART (plain or VCOM over USB) with another piece of software running on the TL-WR703N that basically monitors the Arduino board output and forward it to the server by sending HTTP get/post requests. The CGI on the server then have to parse the request and do whatever is required to store the values within the database.

The software on the TL-WR703N can be a shell/Lua/Python script or a dedicated binary executable.

The transport over USB vs. plain UART, or Wifi vs. Ethernet doesn't add anything to the problem.


I need a "getting started document" or some basic/simple examples on only piece of software running on the TL-WR703N. Other software pieces are okey. Im new on OpenWRT, embedded Linux, Shell, Lua, Python. If possible, please redirect me to learn these. Where and how do I start?

>I need a "getting started document" or some basic/simple examples on only piece of software running on the TL-WR703N

From the link I provided, post 3

#!/bin/sh
stty -F /dev/ttyUSB0 2400 clocal cread cs8 -cstopb -parenb -crtscts
cat /dev/ttyUSB0 2>/dev/null | while read v1 v2 v3 v4; do
  echo "$v1 $v2 $v3 $v4 $(date +%y%m%d%H%M%S)" >> /home/user0/Rx01.txt
  echo "$v1 $v2 $v3 $v4 $(date +%y%m%d%H%M%S)" | nc 192.168.1.70 8086 &
  sleep 1s ; kill `pidof nc`
done

If the arduino is sending lines terminated with "lf", this is all you would need on the WR703N (started, for instance, by putting this in a script and running the script in /etc/rc.local (disconnecting from the terminal with "&" at the end)).  The script logs the line it receives with a timestamp to a local file and sends it on with "nc" to another device.

Check the rest of the thread for variations and to see one way to handle it on the receiving device (192.168.1.70).

Note that the WR703N has a glitch involving the simultaneous use of usb/serial and wifi--the serial locks up after a period.  To avoid this problem, use a usb 2.0 hub on the WR703N which reports in dmesg as "high speed", not "full speed".  See this thread for more information (page 4 for the solution): https://forum.openwrt.org/viewtopic.php?id=39956

(Last edited by lizby on 27 Jan 2013, 23:14)

What works may depend on the type of usb/serial dongle you have.  Today I plugged a CH340 serial dongle into a ramips device, and it wasn't recognized at all.  I installed kmod-usb-ochi and it was recognized.  It worked with picocom, but did not work with the script I quoted above.

This was baffling.  I replaced the CH340 device with a CP2102 device.  That worked without the ohci module, and the script worked without problems.  I assume this is a driver issue, but I have no idea what the problem can be.

I have encountered the problem before of a serial usb device working in picocom but not in lua or with a script, and have replaced the device thinking that it was somehow faulty--it may just be the ChipHead driver.

The discussion might have continued from here.