Our full technical support staff does not monitor this forum. If you need assistance from a member of our staff, please submit your question from the Ask a Question page.


Log in or register to post/reply in the forum.

using http protocol


moho Oct 1, 2008 06:44 PM

Hello togehter,

first of all. Congratulations, for the new CS Forum. :)

Actually, I have a question about using http protocol, after getting a ppp connection. Is it possible to open an standard url: like the way as in a browser?

The ppp ip I get from the operater is a public dynamic ip.

Which function should use in crbasic programming

Thx


jra Oct 2, 2008 01:28 PM

Welcome to the CSI Forum moho,

I'm not sure I understand your question. Do you want your datalogger to act like a browser or do you want to browse to your datalogger?

To help you narrow down which instruction(s) to use, use the drop down box,in the CRBasic editor Instruction Panel, to show only the Internet Protocols instructions. Select an instruction then press the Help button. At the top of each instruction's Help dialog box is a link to an Example program.

Take a look at the WebPageBegin/WebPageEnd instruction details and Example. I think that will get you started. If not, please post more details on what you are trying to do.

Regards,
Janet


moho Oct 2, 2008 02:00 PM

Hi Janet,
well I found an answer in a similar question. And I did some tests today. The result is, that the listed crbasic code will do, what I want.

<paste in CRBasic>

'CR1000 Series Datalogger
'Program example of dyndns update
'Refer to http://www.dyndns.com/developers/specs/syntax.html - Raw HTTP GET Request

'Declare Public Variables
Public PTemp_C
'Declare Variables for dyndns updaate
Public Socket
Public SocketResponse As String * 200
Public SocketGetRequest As String * 200
Public dyndnshostname As String * 200
Public dyndnsauth As String * 200

'Main Program
BeginProg
Scan(1,Sec,0,0)
'Wiring Panel Temperature measurement PTemp_C
PanelTemp(PTemp_C,_50Hz)
NextScan

SlowSequence
Scan(10,Min,0,0)
dyndnshostname="YOURACCOUNT.dyndns.org"
'base-64-authorization crypted
dyndnsauth="USERNAME:PASSWORD"
SocketGetRequest="GET /nic/update?hostname="+dyndnshostname+"&myip=ipaddress&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG HTTP/1.0"+CHR(13)+CHR(10)
Socket=TCPOpen("members.dyndns.org",80,1024)
If Socket<>0 Then
'Transmit GET request
SerialOut(Socket,SocketGetRequest,"",0,0)
'Based on tests a Host request-header field is required
SerialOut(Socket,"Host: members.dyndns.org "+CHR(13)+CHR(10),"",0,0)
'Based on tests a base-64-authorization request-header field is required
SerialOut(Socket,"Authorization: Basic "+dyndnsauth+CHR(13)+CHR(10),"",0,0)
'Based on tests a legitimate User-Agent request-header field is required
SerialOut(Socket,"User-Agent: Company - Device - Version"+CHR(13)+CHR(10),"",0,0)
'Based on tests a final blank line (carriage return and line feed) is required
SerialOut(Socket,CHR(13)+CHR(10),"",0,0)
'Capture the GET request response for debugging purposes
SerialIn(SocketResponse,Socket,500,"",200)
EndIf

NextScan
EndProg


What I need now, is to bring the dyndns update procedure in a sub function and only use it, when the PPPOpen command success and I will get an IP in status table.

Thanks for help ;)


IslandMan Oct 3, 2008 08:44 AM

Moho,

Could you explain what this program does?

Thanks,
Dave


jra Oct 3, 2008 03:01 PM

Hello Moho,
You wrote:
>What I need now, is to bring the dyndns update procedure
>in a sub function and only use it, when the PPPOpen
>command success and I will get an IP in status table.

You can call a subroutine based on the status of the PPPOpen instruction like this:

<<<<<<<<<<<<<< program <<<<<<<<<<<
Public flag As Boolean, P3Open As String

'Define Subroutines
Sub update
' EnterSub instructions here
EndSub

'Main Program
BeginProg
Scan (1,Sec,0,0)
P3Open = PPPOpen
If P3Open <> "0.0.0.0" Then flag = true
If flag = true Then Call update
NextScan
EndProg

<<<<<<<<<<<<<< end program <<<<<<<<<<<

Let me know if that answers your question.

Have a good weekend.
Janet


moho Oct 3, 2008 06:39 PM

Hello Janet and IslandMan,
thanks for your answers. I have written my question here, before I read the question in IslandMans topic, about the "Weather Underground Upload". This helps me a lot. I could used the code snipped to adapt my code for my use. Now,
the subroutine will be used, for the update procedure after getting IP from the PPPopen.

@IslandsMan
Regarding your question, what does the code do?

Well, have a look at the posted link in my header of the crbasic programm. There I linked to the specifications of the service by dyndns.org
(It could be possible, that this is not interesting for those, who get "fixed public IPs" with their communication device connected to the data logger eg. modem It depends of the country and the provider) With this service I can now find my data logger wordwide in the internet. ->solution for dynamically IP adresses.

<from webpage>
Dynamic DNS (DDNS) allows you to create a hostname that points to your dynamic IP or static IP address or URL...

best wishes, Tim

@Janet
The forum helps me within less than two days! perfect Thanks a lot campbell, for the decision of a forum. It teams people togehter! Thumbs Up :)
- I think for the future, the forum should use some categories, eg. crbasic codes snippets
- thanks for the ppp subroutine

..sorry for the misunderstanding, english is not my mother tongue ;)

* Last updated by: moho on 10/3/2008 @ 12:46 PM *


Anthony Oct 7, 2008 07:57 AM

Dear all,

we have simular problem.
This is the situation:
a CR1000 with WaveCom Fasttrack GPRS.

In the CrBasic, there is a slow sequence which is used when the Wavecom GPRS modem is assigned a new IP adres from te UMTS network.

'The SlowSequence instruction allows one or more instructions to be executed at a different rate than that of the main program.
'SlowSequence is used to check if the logger has lost connection to Loggernet and reset it if necessary
SlowSequence

'Every minute
Scan(60,sec,1,0)

'If the modem has not been initialised turn off the auto-reset function
If NOT modeminitialised Then
SerialOpen(Modemport,9600,0,2000,1000)
'The SerialOut function is used to transmit a string over one of the datalogger's communication ports.
'Syntax: SerialOut ( ComPort, OutString, WaitString, NumberTries, TimeOut )
SerialOut(Modemport,"+++","+++",3,200) 'Get the modem's attention
Delay(0,1,sec) '+++ guard time
SerialOut(Modemport,"ATZ"+CHR(13),"0"+CHR(13),3,200)
SerialOut(Modemport,"AT+WRST=0"+CHR(13),"0"+CHR(13),2,200)
SerialClose(Modemport)
modeminitialised=true
EndIf

'Check if there is a route back to the Loggernet server
'(change the Pakbus of the server to match)
'The Route function is used to return the neighbor address of (or the route to) a PakBus datalogger.
If Route(4094)<>4094 Then offlinecount=offlinecount+1 Else offlinecount=0

'If no connection for ten minutes
'(or change to suit - beware it can take up to 5 mins for old links to time out)
If offlinecount>=6 Then
SerialOpen(Modemport,9600,0,20000,1000)
SerialOut(Modemport,"+++","+++",3,200) 'Get the modem's attention
Delay(0,1,sec) '+++ guard time
SerialOut(Modemport,"ATZ"+CHR(13),"0"+CHR(13),3,100) 'Reset to be sure
'Turn on the highest level of status reporting WAVECOM Specific
SerialOut(Modemport,"AT+WIND=255"+CHR(13),"0"+CHR(13),1,200)
'Issue the soft reset command and wait until fully online (WIND: 4)
SerialOut(Modemport,"at+cfun=1"+CHR(13),"+WIND: 4",1,5000)
SerialClose(Modemport) 'Done
offlinecount=0 'Reset the counter/timer
EndIf
NextScan 'end slowsequence

In the Loggernet Setup, the IPPort is set with 'Call-back eneble' and 'Cache IP-address' enabled.


If Loggernet is runned on a computer connected to internet via fixed IP, everything works fine.
In "CSI Device Config Utility" for CR1000,
PackBus/TCP server is set to the fixed IPaddress


If Loggernet is runned on a computer connected to internet
also via GPRS (dynamic DNS via dyndns.org), we have problems not getting connection when loggernet was interrupted for a long periode (more then 15 min).
In "CSI Device Config Utility" for CR1000,
PackBus/TCP server is set to MYHOST.dyndns.org


We suspect that the CR1000 call-back routine to the IP adres of the computer, is not updated when the slowsequence starts.

Can somebody give us advice

Many thanks

Anthony


moho Oct 7, 2008 08:49 AM

Hi Anthony,
I can not give advice but maybe some ideas. We are still testing the different ways. Our system looks like:

CR1000 + CS-GPRS Set
This will be setted as in the manual cs-gprs.pdf written. So all settings should be made with device utility. Especially the response code 21, which means, that the ppp connection is established.

LoggerNet settings
The LoggerNet PC is in our company network and the main router will forward incoming ports (eg. 6785-6790) to it. Our public IP is a dynamical IP adress. Because it is a adsl-line (digital subscriber line). So we use the dyndns service in the company. The settings we made in the device utility of cr1000 are in ServiceSetting: YOURACCOUNT.dyndns.org:6785 eg. for the first logger. the second will get a different port. Our local campbell dealer, said that we have to do it with different ports.

- These system with the described settings runs 14 days with no problems. But we did never now the actually IP adress of the ppp(connection) (modem). That was the reason, why I asked for the procedure to use also the dyndns.org service in the crbasic code (logger), as in some topics above described.

For our company it is very important to have full backup solutions for the communication. We will develop following situations in the next weeks:

CR1000+cs-GPRS (logger) <-> LoggerNet (PC)

GPRS
1. Logger initialized communication to PC -> Callback cs-gprs.pdf
2. PC initialized communication to logger -> dns service is needed, in case of public dynamical IPs, to find the system


controled with rtime and pppclose/open in the crBasic code we will use also:

GSM
1. PC initialized communication to logger as described in cs-gsm (eg. If the gprs connection is not working, we will have time to use two hours of the day, without gprs set)
2. Logger initialized communication to PC, with function ModemCallback and maybe sendvariables... (This is a way, that should be controlled for example, when on the serial interface the modem does not see a incoming RING for a setted time. Than it should call back automatically to the PC.)


We have a lot of systems outside in Europe and have still some problems, that sometimes the provider change their settings of the network. And the system is not available any more. We think that for example the single numbering scheme could be the problem. Eg. AT+CSNS=4 helped us.
Which means:
The AT+CSNS command enables the ME to accept incoming calls when no bearer capability information is provided
with the call, e.g. single numbering scheme calls or calls originating from analog devices.

Well a lot of things to do and to test, but we have not too much time ;)

Hope maybe campbell can develop a fail back-solution.

Many greets
Tim (moho)

UPDATE
@Anthony
Have a look at the cs-gprs.pdf manual. On page six is written, that you can set these parametes (AT Commands) via device utility.

-> that is the way we do!

If you intend to run the modem without turning power off to it and without
resetting the modem under program control, it is advisable to include commands
to reset the modem either at regular intervals or at the start of the dialling process.
The latter ensures the modem logs off the GSM network and reconnects each time
before dialling. This process can extend the dialling process by 10 s or so and
may not function in the same way with all modems. This will only work with an
up-to-date version of the logger operating system that allows “;” to be used to
force delays in the dial string. To reset the modem include the command
AT+CFUN=1 at the start of the dial string, followed by at least five extra “;” to
allow the modem 5 seconds to reset before subsequent commands are sent. This
would make the full dial string, including the APN setting like this:
‘AT+CFUN=1;;;;;;AT+CGDCONT=1,”IP”,”servername”;ATD*99***1#’

Maybe this will help you!

greets

* Last updated by: moho on 10/7/2008 @ 3:17 AM *


IslandMan Oct 7, 2008 10:06 AM

Tim (moho)

Thanks for the information.
I'm new to this so still a little confused.

Here is my project. We are doing some monitoring for "Green Building" application.

We will have a computer, connected to the internet running Loggernet in a separate location. CR1000 and NL115 will be installed in a hotel that has Internet capability for the guests. NL115 will be attached to the network in the hotel.

If I understand all this correctly, we can set up an account at dyndns.org. We put the hostname@dyndns.org into the NL115.
We run Loggernet with callback enabled and cashe IP enabled.
We put the code you had into the logger program. The logger tells the Loggernet what IP address it has and we can communicate?

I have a CR1000 and NL115 here connected to my wireless network with a bridge. I'd like to test this here before putting it out into the field.

Appreciate any help you can give in getting this set up.

Thanks,
Dave


moho Oct 7, 2008 10:47 AM

Hi Dave (IslandMan), ;)

Well, NO we are now mixing things.

In your project you have to set up CR1000 and the NL115 as in the nl115.pdf manual written, page 1-4 (1.5.2 Communication via Ethernet). Follow the steps 1 to 3.

Step 1b Use DeviceConfig Tool for settings...

Step 1c needs an IP -> This should be an IP in the network, where the CR1000 with NL115 is connected. eg. the hotel network or your home network. (often: 192.168.0.2, subnetmask could be 255.255.255.0, gateway will be the routers or modems internal IP eg. 192.168.0.1) SEE also section 2.8 for DHCP use. Then this will be done automatically. I would prefer to use static IP.

Now you set up the way, that the logger can communicate with the internet (outwards) but not for incoming direction. You need to set up a route in the router/modem, like a port forwarding rule, that forward each connection from the internet with the port eg. 6785 to the data logger IP(nl115), which you have set up in step 1c.

Most of the routers/modem (in Europe) uses already installed tools and scripts for dyndns.org services. Otherwise you could try it with the script I posted severals above. This could work. (not tested)

ATTENTION, check all Firewall settings!!!

Now your Logger can be seen from internet, eg. if http or ftp is enabled! (and for sure the ports should be forwarded)

You can use LoggerNet Settings as in Step 2 of the manual described. In step 2b an Ip should insert. There you can now insert the account of the dyndns.org service, if your internet profider uses dynamical IPs eg: MYLOGGER.dyndns.org:6785 or set the fixed IP of the router/modem. (I do not know what you are using!)

LoggerNet then connect to the router/modem, then will be forwarded and find the nl115 with data logger.


Hope you understand this.... ;)

See also section 2.1.1 There is an example of crbasic code, which will do the callback to loggernet (Attention: this is the IP of the way to your LoggerNet PC)

Questions:
- What kind of internet connections?
- Dynamic or Fix IP?
- public or private?

greets moho


Anthony Oct 7, 2008 02:58 PM

Hi all,

thanks for the response, but it will help not for my problem.

If the connection is lost for a longer periode between the loggernet (dynamic IP via GPRS) and the CR1000 (also dynamic IP via GPRS), both sites (loggernet & CR1000) will have a new IP adres received from the GPRS network and then the call-back is not working, because the Cr1000 does not know the new IP adres from the computer which runs loggernet.
When cold-restarting the CR1000 (disconnect power), the connection will come up again. This is because the PakBus/TCP server settings "MYHOST.dyndns.org", programmed in the CR1000 via the DevConf software is, as I assume, updated after a cold restart.
Is there a way to do the update via the CrBasic software while perfoming the slow sequence, or after checking if the GPRS IP is changed, or....? Maybe something like Janet proposed in her post of 10/03/08 9:01 AM.


Kind regards,

Anthony


moho Oct 7, 2008 05:16 PM

Hi Anthony,
I can not test it, but try code below:
greets Tim


'CR1000 Series Datalogger
'Program example of dyndns update with Subroutines
'Refer to http://www.dyndns.com/developers/specs/syntax.html - Raw HTTP GET Request
'Please read CampbellSci manual: cs_gprs_jul08.pdf Section 6

'Declare Public Variables for measuring
Public PTemp_C

'Declare Public Variables for PPP Ip
Public P3Open As String * 20
Public P3flag As Boolean

'Declare Variables for Subroutines DNS dyndns updaate
Public DyndnsSocket
Public DyndnsSocketResponse As String * 200
Public DyndnsSocketGetRequest As String * 200
Public DyndnsHostname As String * 200
Public DyndnsAuth As String * 200
Public DyndnsMyIP As String * 20
Public DyndnsWildcard As String * 20
Public DyndnsMx As String * 20
Public DyndnsBackMx As String * 20

'Define Subroutines DNS dyndns udpate
Sub update
'Use your dyndns account settings
DyndnsHostname="YOURACCOUNT.dyndns.org"
'base-64-authorization crypted
'check eg. http://www.motobit.com/util/base64-decoder-encoder.asp
DyndnsAuth="USERNAME:PASSWORD"
DyndnsMyIP="ipaddress"
DyndnsWildcard="NOCHG"
DyndnsMx="NOCHG"
DyndnsBackmx="NOCHG"
DyndnsSocketGetRequest="GET /nic/update?hostname="+DyndnsHostname+"&myip="+DyndnsMyIP+"&wildcard="+DynDnsWildcard+"&mx="+DynDnsMx+"&backmx="+DynDnsBackmx+" HTTP/1.0"+CHR(13)+CHR(10)
DyndnsSocket=TCPOpen("members.dyndns.org",80,1024)
If DyndnsSocket<>0 Then
'Transmit GET request
SerialOut(DyndnsSocket,DyndnsSocketGetRequest,"",0,0)
'Based on tests a Host request-header field is required
SerialOut(DyndnsSocket,"Host: members.dyndns.org "+CHR(13)+CHR(10),"",0,0)
'Based on tests a base-64-authorization request-header field is required
SerialOut(DyndnsSocket,"Authorization: Basic "+DyndnsAuth+CHR(13)+CHR(10),"",0,0)
'Based on tests a legitimate User-Agent request-header field is required
SerialOut(DyndnsSocket,"User-Agent: Company - Device - Version"+CHR(13)+CHR(10),"",0,0)
'Based on tests a final blank line (carriage return and line feed) is required
SerialOut(DyndnsSocket,CHR(13)+CHR(10),"",0,0)
'Capture the GET request response for debugging purposes
SerialIn(DyndnsSocketResponse,DyndnsSocket,500,"",200)
EndIf
EndSub

'Main Program
BeginProg
Scan(1,Sec,0,0)
'Wiring Panel Temperature measurement PTemp_C
PanelTemp(PTemp_C,_50Hz)
NextScan

SlowSequence
Scan(1,Min,0,0)
'Check if PPP IP has changed every minute by Janet 10/03/08 9:01 AM
P3Open = PPPOpen
If P3Open <> "0.0.0.0" Then P3flag = true
If P3flag = true Then Call update
NextScan
EndProg


aps Oct 8, 2008 11:24 AM

A couple of points of warning on use of a dynamic DNS solution

1) if you are using a GPRS connection, many cellnet companys only provide a dynamic PRIVATE IP address where you have an IP address in one of the private network ranges and your connection to the Internet is via a router. In this instance the dynamic DNS entry you get at the Loggernet end of the link, will usually be for the router, not your modem and will not allow you to connect to the logger from a PC on the public internet.

2) if you find dynamic dns does work (your cellnet provider issues public addresses or you are using an NL115 directly on the internet) make sure that in Loggernet the option to "Cache the IP address" is not checked, to ensure a fresh lookup is done every time.

With regards as to whether the Logger is caching the lookup of the server URL it calls back to I will check this out and post and update. Ideally it should not.

APS


moho Oct 8, 2008 12:25 PM

Hi aps,
thanks for the information about disabeling the option "caching the IP address". Very helpfull information.

Do you know or have a list of cellnet providers in europe, who are using public or private IPs?

I found an interesting guideline:
Guidelines for IPv4 Addressing and AS
Numbering for GRX/IPX Network Infrastructure
and User Terminals

See: http://www.gsmworld.com/documents/prd/ir4040.pdf

There is written, that sometimes the providers have different APNs (Access Point Names) which offers then public or private IPs.

What is your experience?


IslandMan Oct 8, 2008 03:08 PM

Greetings Tim aka moho,

Thanks for the input. I was researching this yesterday but then got busy.

I have Verizon here at my office. Have a wireless router and access to it. I am able to set port forwarding in the router. I believe that the IP address of my router is dynamic, that is if I turn it off and on again I will get a new IP address. (I haven't confirmed that but will do so.)

I've printed and read your instructions several times and it's starting to sink in. I have the NL115 set up just as you suggested.
Fixed IP on my LAN of 192.168.1.3
Subnet Mask 255.255.255.0
IP Gateway 192.168.1.1
DNS Server 192.168.1.1
FTP and HTTP are all enabled.

I previously had this logger doing email and FTP so I know it goes out to the net ok.

I will set up account at dyndns and see if I can get this to work. If it works here, I should be able to make it work at the hotel if I can get access to the router there and enable the port forwarding.

Will report back, hopefully with success.

Best Regards,
Dave (IslandMan)


Dana Oct 8, 2008 03:35 PM

Hello All,

I don't know if I am following all of this, but...

Keep in mind that the "Cache IP Address" setting does just that -- when enabled, LoggerNet will remember the datalogger's last used IP address. If this setting is disabled, LoggerNet will resolve the IP address each time it tries to connect.

If the IP address is always changing, it would seem that a cached IP could be problematic.

I hope this sparks some ideas :)

Regards,

Dana


ChipsNSalsa Oct 8, 2008 04:49 PM

If both the LoggerNet side and the CR1000 side of the IP link are dynamic then the DNS service is probably the way to go. The only other way I can think of to deal with both sides of the connection being dynamic is to put a CR1000 PakBus server/router out on the Internet with a public static IP address. Both LoggerNet and the CR1000 could maintain connections to it and it would essentially function as a middleman between the two (or more) dynamic IP address sides. If however the LoggerNet side has a static IP and the CR1000 side has a dynamic IP and/or is firewalled, which is often the case, there's another way.

In the LoggerNet setup screen you would configure:

IPPort - call-back enabled, TCP listen only enabled, cache IP address disabled (:6785 will be shown in the Internet IP address field), and IP port used for call-back set to 6785 (the NL115s default port number)

PakBusPort - PakBus port always open enabled

CR1000 - Call-back enabled


Using DevConfig to configure the CR1000 you would enter the static public IP address of the router the LoggerNet computer is connected to the Internet with into the PakBus/TCP Server field on the Net Services tab on the Deployment tab and leave the PakBus/TCP Port set to 6785 (the default).

In the router on the LoggerNet side forward port 6785 to the computer that's running LoggerNet. If there's a firewall/router on the CR1000 side nothing will likely need be done to it unless it's blocking outbound ports because the CR1000 will be making the outbound connection to the LoggerNet computer.

With this setup the CR1000 should initiate the IP connection to the LoggerNet computer and the LoggerNet computer should maintain it because PakBus Port Always Open is enabled. If the IP address of the CR1000 changes it will initiate a new IP connection to the LoggerNet computer and the old connection will die.

For all CR1000s setup to initiate a connection to the same LoggerNet in this fashion you'll need to specify a unique port number in the "IP port used for call-back" in the Setup screen, the "PakBus/TCP Port" of the CR1000, and forward the port in the router on the LoggerNet side.


ChipsNSalsa Oct 8, 2008 04:57 PM

I agree with Dana on the cache IP address point. That's why in my example I specified Cache IP Address disabled. I also specified TCP Listen Only enabled because LoggerNet likely cannot initiate a connection to the CR1000 if it's firewalled and should not try.


aps Oct 9, 2008 04:33 PM

I checked with the developer and the logger should lookup a new IP if the TTL setting for that URL has expired. It will do this when it attempts to open the socket to the remote server.

If a connection to a socket has been established the logger will not trigger a look-up of DNS when the TTL expires to check if it changed though (most systems won't). It will only do a lookup next time it opens the socket.

If the Loggernet server goes offline in a controlled fashion and the logger gets a normal close socket message, if in the automatic connect mode, it will try and reopen the socket at regular intervals checking the DNS entry. If however, Loggernet goes offline without shutting the socket cleanly, it can take the logger some while to detect the broken connection, especially if the PPP link is still up.

The only way to improve on this is to regularly close and open the socket from within the program. Currently there is no way to do a DNS lookup and return the IP address of a remote device to the program, which might otherwise let you get an earlier indication that the Loggernet server has changed its IP address.

Please lookout for the next release of the operating system for the CR800/1000/3000 dataloggers which is due in a few weeks as this includes some minor enhancements, in particular in timing out broken connections, plus there is now a ping instruction that allows you to check a connection independent of the logger's own mechanisms.


aps Oct 9, 2008 04:49 PM

A separate point regarding cellphone networks and fixed IP. In Europe only a few network providers directly offer a fixed IP service. Most fixed IP services are provided by third parties who provide specially registered SIMs and a different APN server on the cell network.

When you use that APN you still get a private IP address and either a VPN connection to the same subnet OR they map the address in a router to a public IP address.

There are quite a few of these providers. I know of:

Wyless (wyless.net) and Mobius (http://www.mobiusnetworks.co.uk/) in the UK
Kuantic in France and Italy.

Using the call-back procedure can work quite successfully as previously described. More details can be found in here:

ftp://ftp.campbellsci.co.uk/pub/csl/outgoing/uk/manuals/cs_gprs_jul08.pdf


aps Oct 16, 2008 03:05 PM

Below is an updated version of the previously posted program for registering with dyndns. This has a modification to the code which controls registering the new address. Reason is that if you keep firing registration requests at dyndns every minutes when your IP has not changed you will get blocked.

This needs more testing. If someone is able to do this and report we'd be grateful as it may be a while before I can do this:


---
'CR1000 Series Datalogger
'Program example of dyndns update with Subroutines
'Refer to http://www.dyndns.com/developers/specs/syntax.html - Raw HTTP GET Request
'Please read CampbellSci manual: cs_gprs_jul08.pdf Section 6

'Modified by APS (15 Oct 08) so checks against IP it had on the previous scan to avoid getting
'blocked. Also tidied the structure a little.
'Note: needs testing and entry of a unique Company, Device and version to comply with DynDNS spec.

'Declare Public Variables for measuring
Public PTemp_C

'Declare Public Variables for PPP Ip
Public P3Open As String * 20, lastIP As String *20, response As String


'Define Subroutines DNS dyndns udpate - now with parameters. Sends what the logger thinks the IP is.
Sub update(DyndnsMyIP As String * 20, DyndnsSocketResponse As String)

'Variables only used in this subroutine
Public DyndnsSocket
Public DyndnsSocketGetRequest As String * 200

'Use your dyndns account settings - defined as constants
Const DyndnsHostname="YOURACCOUNT.dyndns.org"
'base-64-authorization crypted of USERNAME:PASSWORD
'check eg. http://www.motobit.com/util/base64-decoder-encoder.asp
Const DyndnsAuth="USERNAME:PASSWORD"
Const DyndnsWildcard="NOCHG"
Const DyndnsMx="NOCHG"
Const DyndnsBackMx="NOCHG"

DyndnsSocketResponse ="" 'to be sure we can detect no response

DyndnsSocketGetRequest="GET /nic/update?hostname="+DyndnsHostname+"&myip="+DyndnsMyIP+"&wildcard="+DyndnsWildcard+"&mx="+DyndnsMx+"&backmx="+DyndnsBackMx+" HTTP/1.0"+CHR(13)+CHR(10)
DyndnsSocket=TCPOpen("members.dyndns.org",80,1024)
If DyndnsSocket<>0 Then
'Transmit GET request
SerialOut(DyndnsSocket,DyndnsSocketGetRequest,"",0,0)
'Based on tests a Host request-header field is required
SerialOut(DyndnsSocket,"Host: members.dyndns.org "+CHR(13)+CHR(10),"",0,0)
'Based on tests a base-64-authorization request-header field is required
SerialOut(DyndnsSocket,"Authorization: Basic "+DyndnsAuth+CHR(13)+CHR(10),"",0,0)
'Based on tests a legitimate User-Agent request-header field is required
SerialOut(DyndnsSocket,"User-Agent: Company - Device - Version"+CHR(13)+CHR(10),"",0,0)
'Based on tests a final blank line (carriage return and line feed) is required
SerialOut(DyndnsSocket,CHR(13)+CHR(10),"",0,0)
'Capture the GET request response for debugging purposes
SerialIn(DyndnsSocketResponse,DyndnsSocket,500,"",200)
EndIf
EndSub

'Main Program
BeginProg
lastIP="" 'To make evident it is set to null at start so registered on first connection

Scan(1,Sec,0,0)
'Wiring Panel Temperature measurement PTemp_C
PanelTemp(PTemp_C,_50Hz)
NextScan

SlowSequence
Scan(1,Min,0,0)
'Check if PPP IP has changed every minute by Janet 10/03/08 9:01 AM

P3Open = PPPOpen 'Get our current IP address
If P3Open <> "0.0.0.0" Then 'If 0.0.0.0 don't bother as we don't currently have a working PPP connection
If P3Open <> lastIP Then Call update(P3Open,response) 'IF changed then Register the new IP with dyndns
If response = "good" OR response ="nochg" Then lastIP=P3Open 'Update the lastIP value as it was registered OK
EndIf
NextScan
EndProg


IslandMan Oct 24, 2008 03:30 PM

Hello,

Finally got some time to test the dyndns.org with my CR1000 and NL115 setup.

I've set up an account at dyndns.org.
I can ping adamsenv.dyndns.org and that comes back to my verizon router ip address.
I've set up forwarding of port 6785 in my router for the IP address of my NL115, 109.168.1.6
I'm not sure if I have this correct
Verizon Supplied Router is ActionTec

Networked Computer / Device:192.168.1.6
Rule Name DNS - Domain Name Server
TCP 53 -> 53 1024-65535 -> 53
UDP 53 -> 53 1024-65535 -> 53
WAN Connection Type:Ethernet
Forward to Port:6785
When should this rule occur ?Always

I have put adamsenv.dyndns.org:6785 in my loggernet but it will not connect.

Any Ideas?

Do I have to put the "Program example of dyndns update with Subroutines" in the logger?

Thanks,
IslandMan


aps Oct 27, 2008 03:37 PM

The example posted before was for when the logger is directly on the Internet and can detect a change of IP address. If its detects a change of address it then re-registers itself with dyndns.org

In your setup the logger is behind a NAT router so will always have a fixed private IP address of the internal network, so it will never call back after its intial setup so the last program published will not work too well.

You have a number of options. First, as recommended early on in this discussion, is that you investigate whether the router supports dyndns in its own right - many do these days. If it does and it is setup correctly it will register its own address correctly when it detects the change and will be the most reliable solution.

The second option is to modify the logger program such that it just re-registers itself with dyndns on a regular timed basis without checking its own IP. However, if your IP is not changing you risk getting barred by dyndns for breaching its T&Cs.

The third option is to work out how the logger can find out its own apparent IP address on internet (its router's IP address) and if that changes re-register with dyndns. There are tools available to do this for PC based applications (there is one on dyndns) but someone would have to work out how to do this on the logger.


APS


IslandMan Oct 28, 2008 07:26 PM

Andrew,

Thanks for the reply and suggestions.

I think the safest bet is to tell my client that he has to get a fixed IP address for the NL115 so it's on the Internet.

Regards,
Dave


aps Oct 29, 2008 09:23 AM

A fixed IP address is always the simplest option!

However, one other idea. If the internet router does not support dyndns directly (as I said most new ones do), see if it can be set to work in "routed" mode rather than "NAT" mode.

In routed mode devices on the internal network get public IPs and the router acts in a more transparent way - there is no need to port forward. The NL115 will then appear to be directly on the internet and the logger will be able to detect changes in its IP address, so the last example program posted should work.

Being able to work in routed mode is not uncommon even for home routers, but is rarely used as you it normally limits you to one device per router, unless you are assigned a batch of IP addresses (which are usually fixed).


SJG Sep 23, 2009 11:33 PM

Check the code below for a way to extract the outside world IP of your gateway:

www.whatismyip.com has a URL which returns the Ip of the gateway when you run it.
The split, if successful data is received will always place the IP if the 20th field of the array.

Remember though, to connect directly inbound you need a 'proper' IP, and the ports need to be forwarded to your device AND your device needs a static IP on the local network.

Steve


'CR1000 Series Datalogger
'To create a different opening program template, type in new
'instructions and select Template | Save as Default Template
'date:
'program author:

'Declare Public Variables
'Example:
Public PTemp, batt_volt
Public GetString As String * 200
Public ReturnString As String * 400

Public Socket
Public SocketResponse As String * 400
Public SocketGetRequest As String * 400
Public SplitResponse(20) As String * 50

'Declare Other Variables
'Example:
'Dim Counter

'Declare Constants
'Example:
'CONST PI = 3.141592654

'Define Data Tables
DataTable (Test,1,1000)
DataInterval (0,10,Sec,10)
Minimum (1,batt_volt,FP2,0,False)
Sample (1,PTemp,FP2)
EndTable

'Define Subroutines
'Sub
'EnterSub instructions here
'EndSub

'Main Program
BeginProg

SocketGetRequest = "GET http://www.whatismyip.com/automation/n09230945.asp"+CHR(13)+CHR(10)
Scan (10,Sec,0,0)
PanelTemp (PTemp,250)
Battery (Batt_volt)

Socket = 0
SocketResponse = ""
Socket=TCPOpen("www.whatismyip.com",80,1024)
If Socket<>0 Then
'Transmit GET request
SerialOut(Socket,SocketGetRequest,"",0,0)

'Based on tests a Host request-header field is required
SerialOut(Socket,"Host: www.whatismyip.com "+CHR(13)+CHR(10),"",0,0)
'CR LF
SerialOut(Socket,CHR(13)+CHR(10),"",0,0)

'Capture the GET request response for debugging purposes
SerialIn(SocketResponse,Socket,900,"",400)

SplitStr (SplitResponse(),SocketResponse,CHR(10),20,14)




'a typical response
' HTTP/1.1 200 OK
' Date: Wed, 23 Sep 2009 22:07:57 GMT
' Server: Microsoft-IIS/6.0
' X-Powered-By: ASP.NET
' Content-Length: 14
' Content-Type: text/html
' Set-Cookie: ASPSESSIONIDSSQBABTB=BKHCFJABGCGOAOOKIBDPECLE; path=/
' Cache-control: private
'
' 71.71.71.218

EndIf

CallTable Test
NextScan
EndProg

* Last updated by: SJG on 9/23/2009 @ 5:36 PM *


JC Oct 1, 2009 10:56 PM

Steve,

Very nice example how to get a dynamic IP. I'm testing your code, but I can't find the way to get the response:

' HTTP/1.1 200 OK
' Date: Wed, 23 Sep 2009 22:07:57 GMT
' Server: Microsoft-IIS/6.0
' X-Powered-By: ASP.NET
' Content-Length: 14
' Content-Type: text/html
' Set-Cookie: ASPSESSIONIDSSQBABTB=BKHCFJABGCGOAOOKIBDPECLE; path=/
' Cache-control: private
'
' 71.71.71.218

Can you explain how to get the response above.
Thanks,

JC


SJG Oct 2, 2009 12:00 AM

Hi,

I've pasted in the code again, but with a lot more comments.
I'm assuming that you are using the 'connect' screen in loggerNet and that you have a numeric table open with ALL the public variables loaded into it.
Copy all the italics into CRBasic then run Edit-> Rebuild Indentation

One more thing! Do not deploy this application with a scan cycle of 20 seconds.
WhatIsMyIP.com will not enjoy so many requests.
Do it once an hour, or everytime you boot up, or reset your modem.


'WhatIsMyIP.CR1
'** Requires connection to the internet **
'Program makes request to www.whatismyip.com and is returned the source IP of the request.
'The sourceIP is the IP of your gateway, not the IP of your logger.
'Use of this IP is limited to networks where the IP allocated to your gateway is 'real'
'i.e. is a properly resolvable IP.
'Some mobile networks operate in their own APN which will NOT give you inbound connectivity

'Declare Public Variables
'Example:
Public PTemp, batt_volt
Dim i As Long

Public Socket 'a place for the socket number to be stored. 0 if no socket
Public SocketResponse As String * 400 'a place for the response from the whatismyip web server to be stored
Public SocketGetRequest As String * 400 'a place to create the request
Public SplitResponse(20) As String * 50 'somewhere to split the response into
Public MyGatewayIP As String * 50

'Define Data Tables
'doesn't really have any application to this code
DataTable (Test,1,1000)
DataInterval (0,20,Sec,10)
Minimum (1,batt_volt,FP2,0,False)
Sample (1,PTemp,FP2)
EndTable

'Main Program
BeginProg

'Assign the GET request string to appropriate variable
'The GET request is the raw text that is sent to the server
'This is equivalent to what IE or FireFox would send when
'you type : http://www.whatismyip.com/automation/n09230945.asp
'into the address bar - TRY IT!
SocketGetRequest = "GET http://www.whatismyip.com/automation/n09230945.asp"+CHR(13)+CHR(10)

Scan (20,Sec,0,0) ' a nice slow scan rate
PanelTemp (PTemp,250)
Battery (Batt_volt)

'clear the socket variable
Socket = 0
'clear the response variable
SocketResponse = ""
'clear the SplitResponse
For i = 1 To 20
SplitResponse(i) = ""
Next i

'now open a socket to the whatIsMyIP server on port 80
Socket=TCPOpen("www.whatismyip.com",80,1024)

'we can only proceed if a valid socket is opened
'a number other that 0 will be allocated when the socket is open
'with a successful open you will typically be allocated 101
'(so long as you haven't opened any other sockets or ports)
If Socket<>0 Then
'**The following three commands are the equivalent commands that would be
' sent by IE or FFox when you try to browse the page
' http://www.whatismyip.com/automation/n09230945.asp
'**
'Now we can send the HTTP GET request to the server via Serial Out command.
SerialOut(Socket,SocketGetRequest,"",0,0)
'Based on tests, a Host request-header field is required. Send this too
'This +CHR(13)+CHR(10) is a Carriage Return Line Feed ie. CR LF
SerialOut(Socket,"Host: www.whatismyip.com "+CHR(13)+CHR(10),"",0,0)
'Now send a final CR LF to finalise the request
SerialOut(Socket,CHR(13)+CHR(10),"",0,0)

'Now we need to listen for the response back from the server
'The response is stored in socket response
'I can't think of a good terminating character to look for
'so I just wait 9 seconds (900)
'Also, be careful will the Max Chars thing.
'Make sure the SocketResponse is big enough to hold it all.
SerialIn(SocketResponse,Socket,900,"",400)

'now in order to easily extract the IP
'from the response I split the response at the LFs (CHR(10)
'There is about 10 lines in the response, so therefore about 10 LFs
'Your IP is in the last line
'a typical response from the WhatIsMyIP server looks like:
' HTTP/1.1 200 OK
' Date: Wed, 23 Sep 2009 22:07:57 GMT
' Server: Microsoft-IIS/6.0
' X-Powered-By: ASP.NET
' Content-Length: 14
' Content-Type: text/html
' Set-Cookie: ASPSESSIONIDSSQBABTB=BKHCFJABGCGOAOOKIBDPECLE; path=/
' Cache-control: private
'
' 71.71.71.218

'i split the string at the LF character
'I use option 14 which is option 4 and 10 combined
'option 4 is header filter
'adding 10 to it right justifies the results in the array,
'meaning that the IP is always in the 20th element in the array
SplitStr (SplitResponse(),SocketResponse,CHR(10),20,14)

'you can allocate to a variable if you like (probably a good idea as
'the array is cleared every cycle
MyGatewayIP = SplitResponse(20)
'there's a lot more you can do here
'i.e. check that it is a valid IP
' SMS it to yourself once a day
' store it in a cell in your data table
' tell other loggers or loggernet via SendVariables

EndIf
CallTable Test
NextScan
EndProg

* Last updated by: SJG on 10/1/2009 @ 6:05 PM *


James Mar 8, 2010 02:58 PM

Hi Tim / Janet,

I am also interssted at the Cr1000/Wavecom <> Loggernet route via the DYNDNS dynamic update process. How succesfull is the process ?

Sincerely
James


kakha Mar 3, 2014 02:45 PM

Hello all,

I've got one question as well regarding use of PPP protocol, is it possible to use it in order to retrieve data from logger through loggernet? Usually data transfer happens via PakBus protocol but retrieving image file via PakBus takes too long through GPRS maybe because of too much overhead by PakBus.

So I wonder if I can use PPP to retrieve image (only image, no other data) but can't find anything in loggernet to do so, maybe it has something to do in CRBasic?

Thanks in Advance

Log in or register to post/reply in the forum.