Author Topic: HTTP Post  (Read 7550 times)

InfiniteAutomation

  • Newbie
  • Posts: 6
    • View Profile
    • Infinite Automation Systems
HTTP Post
« on: March 06, 2011, 05:44:24 PM »
Hi,  I'm wondering if I could get a little help figurein gout how to have my nano10 make a http post in order to publish data to a remote data logging software.

If it's possible I'm guessing it would be something like:

PRINT #4 "<TCPCONNECT 64.113.32.5:8080>"

but then I need to send something like Temp=DM[50] so it would send the data in dm[50]

Is this possible and could someone help me figure out the formate of this?

Thanks,
Joel.

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3170
    • View Profile
    • Internet Programmable PLCs
Re:HTTP Post
« Reply #1 on: March 06, 2011, 11:43:52 PM »
Does your remote data logging software expect a GET or a POST? GET is more common but you could also send POST.

You need to know what's involved in a HTTP GET or POST protocol in order to write your program.

The following is an example of a GET command sent with parameters in "key=value pairs" to a website that runs a PHP database. To update data you are supposed to set a HTTP GET command (GET is sent when you enter strings such as http:// xxx  into the browser URL field) in the format:

   GET www.xxxxx.com/nano.php?&d1=??&d2=??&d3=?? ....  where d1, d2, d3 are the key and  ?? are the values.



A = A+1
A$ = "GET /nano.php?d1="+STR$(A)
A$ = A$ + "&d2=2&d3=3&d4=4&d5=5&d6=6&d7=7&d8=8"

PRINT #4 "<TCPCONNECT xx.xx.xx.xx:80>"  ' Open connection
DELAY 200
IF STATUS(3) = 0
  B$ = "Failed to connect"
  PRINT #4 "</>"
  RETURN
ELSE
  B$ = "connected"
ENDIF

PRINT #4 A$;
PRINT #4 "&d9=9&d10=10&a3=33&a4=44&a5=55&a6=66";
PRINT #4 " HTTP/1.1"
PRINT #4 "Host:  www.xxxx.com"
PRINT #4 "Connection: close"
PRINT #4 ""
DELAY 1000
FOR I = 1 to 10
  $$[2+I] = INPUT$(4)  ' read responses into C$ to L$ for debugging
NEXT

PRINT #4 "</>"                           'Close connection
DELAY 100

 
« Last Edit: March 06, 2011, 11:46:00 PM by support »
Email: support@triplc.com
Tel: 1-877-TRI-PLCS

InfiniteAutomation

  • Newbie
  • Posts: 6
    • View Profile
    • Infinite Automation Systems
Re:HTTP Post
« Reply #2 on: March 08, 2011, 04:54:16 PM »
That is awesome, thank you so much, I'll have to play around with it to see if it works.

Thanks,
Joel.

EDGAR

  • Jr. Member
  • Posts: 60
  • Automating concepts around the world!
    • View Profile
    • Kinemics
Re:HTTP Post
« Reply #3 on: April 23, 2011, 11:49:53 AM »
Hello,

Im using exact same code above to download xml file from the internet. For some reason or memory reason i can only receive the end of the xml file.  

Do I need to do anything different? Don't matter how I change the code it seems like the variables in function 'input$' is being overwritten as data comes in.

Thanks,
Ed
Low cost Modbus OPC DA Server, supporting Modbus RTU, ASCII, and TCP. Download your demo today! Go to www.kinemics.com/modbus.

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3170
    • View Profile
    • Internet Programmable PLCs
Re:HTTP Post
« Reply #4 on: April 23, 2011, 07:27:41 PM »
INPUT$() can only return Carriage Return (CR) -terminated strings up to 70 characters. It is not designed download an XML file from the internet. Why would you want to do that anyway since the PLC does not execute the XML code?
Email: support@triplc.com
Tel: 1-877-TRI-PLCS

EDGAR

  • Jr. Member
  • Posts: 60
  • Automating concepts around the world!
    • View Profile
    • Kinemics
Re:HTTP Post
« Reply #5 on: April 24, 2011, 05:43:43 AM »
Thanks, I'll be using it to parse information requested from the internet as the time server example does. But my problem is that this file is about 1500 bytes too large.

Thanks,
Ed
Low cost Modbus OPC DA Server, supporting Modbus RTU, ASCII, and TCP. Download your demo today! Go to www.kinemics.com/modbus.