SetCommunicationHandleValue using a DNS instead of IP Address

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.

A few questions for you: What version of firmware are you using? Type of hardware? (SNAP-PAC-R1, maybe?)

What values does your PAC have configured for Gateway/DNS? As shown here in PAC Manager: (should NOT be all zeros, as shown here)


How does that compare to your network’s gateway? From a DOS prompt, ipconfig can help you determine that:

I should mention here that it looks like here you’re using a TCP comm handle to do an HTTP POST. We do have a new-ish PAC Control command: HttpPost. We do have some fixes for that command in the most recent firmware update, click here. Also, we have a chart you can import that shows [URL=“http://www.opto22.com/site/downloads/dl_drilldown.aspx?aid=4163”]how to use those commands, click here.

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!)

Hope that helps.

-OptoMary

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?

Thanks,

Kelly

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?

By the way, my firmware version is R9.2a.

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.

Any thoughts?

Hmm, I still suspect your domain name resolution. Perhaps try this example (that uses URLs on the Internet) to make sure you can resolve names on the Internet: http://www.opto22.com/community/showthread.php?t=393&p=1441&viewfull=1#post1441
(It’s also kind of a fun example that you might want to check out anyway.)

What DNS did you end up using and how did you determine what that should be?

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…

Hope that helps!
-OptoMary