In OptoScript, is it possible to use a DNS instead of an IP address to create a communication handle. I have been trying it. So far, it is not working.
I am trying to send data across using tcp as described on the internetio.com site:
str_php_ip = "vm-ks-dev.dckbengineering.local"; //This is the IP address/DNS of the web server that will be receiving the data.
str_php_port = "80"; //This is the prot of the web server.
str_php_handle = "tcp:" + str_php_ip + ":" + str_php_port;
SetCommunicationHandleValue(str_php_handle, com_php_handle);
FloatToString(flt_engineering_unit, 10,3, str_engineering_unit);
while (GetNthCharacter(str_engineering_unit, 0) == ' ')
GetSubstring(str_engineering_unit, 1, GetStringLength(str_engineering_unit), str_engineering_unit);
wend
//str_watch_string = str_engineering_unit;
str_php_url = "POST http://" + str_php_ip + "/opto_test/test.php?ip_address=" + str_ip_address + "&" + str_tag_name + "=" + str_engineering_unit;
//str_watch_string = str_php_url;
// Now append a CR+LF, your browser normally does this for you, the Apache web server expects it so it knows the URL is done.
str_php_url += chr(13); //append CR
str_php_url += chr(10); //append LF
int_trash_can = OpenOutgoingCommunication(com_php_handle);
// Slight pause while we wait for the network and webserver to respond. Make it longer for slower networks
DelayMsec (100);
int_trash_can = TransmitString(str_php_url, com_php_handle);
// Close the handle so we can do it all again when required.
// Note, Apache will close the IP session now regardless, thus you can ONLY SEND one string per session.
// So if you want to send, say, three bits of info to three different PHP scrips, you will need to use three different com handles!
int_trash_can = CloseCommunication(com_php_handle);
It works when I use the IP address, but not with the DNS.
However, for your case, if your code is working fine w/the IP address, I wouldn’t recommend changing methods at this point. (A comm handle gives you more flexibility and control, and your code looks great, double gold stars for all the nice comments!)
Thanks for your response. I am using SNAP-PAC-R1. I checked the PAC Manager. The Gateway is set up correctly but the DNS is all 0’s
What should the DNS be set to? Should it be the same as the Gateway?
Try 8.8.8.8 (that’s Google’s public DNS – if your gateway is correct then the PAC should be able to get on the Internet and use that public one to resolve the name).
I downloaded the chart that explains how to use the HttpPost command. The string tables won’t load to my controller. When I try to download it, my controller says that the dictionary is full. When I got rid of the string tables, it would download. I noticed that the table each have a length of 100. Do they need to be that large?
I ran our strategy on another PC here in our office using the DNS and it did send data to my in-house web server. So it looks like it works from any computer in our office using SoftPac to use the DNS but it doesn’t work from the controller. I did update the firmware to the latest version.
On my web server (vm-ks-dev), I opened a command window and typed nslookup vm-ks-dev which gave me an IP address of 10.1.1.1. I asked around the office and they said that this was indeed the local DNS server.
I opened up PAC Manager, click on the I/O Unit and then Tools->Inspect->Communications->DNS Resolver and changed the entry for DNS Address Server #0 to 10.1.1.1
I chatted with some in-house networking experts about why your strategy & name resolution would be working fine in SoftPAC but not on your R1. It’s likely that on your Windows machine, that name is being resolved not through DNS but rather through NetBIOS. I found a nice description on the types of “Name Resolution” (search for that key phrase) on this page.
What to do to get it working on your R1 too? Get than name configured on your DNS, if possible. Hopefully your friendly neighborhood IT person will be able to add an entry into whatever is running on that 10.1.1.1 server you mentioned…