3G Forward data to remote emoncms

I have problem with forwarding data to remote url.  Using the ready-to-go SD card image all goes well when connected to home broadband router but when I configure 3G dongle and reboot it stops posting data to remote url but it keeps updating localhost/emoncms. I can browse www so 3G connection is ok.

Wireshark shows HTTP forward data to remote url sent to remote url with home broadband (obvious) but  Wireshark  shows that RPi is not sending HTTP forward data to remote url for 3G connection after RPi reboot. 

"To rectify the process used "I  have to login to dashboard Raspberry Pi and change remote url to false URL and save, then revert changes so url is correct and save again". 

Wireshark trace shown the following during above process:

1.Update with false url below

 

GET /emoncms/raspberrypi/set?frequency=8&sgroup=210&baseid=15&remotedomain=$cms1.wedo.i&remoteapikey=5e5a182a37420e3c22ef48c339c3xxxx HTTP/1.1

2.Update with correct url below:

GET /emoncms/raspberrypi/set?frequency=8&sgroup=210&baseid=15&remotedomain=cms1.wedo.ie&remoteapikey=5e5a182a37420e3c22ef48c339xxxx HTTP/1.1

Now it works the HTTP forward data to remote url is visible in wireshark. Unfortunately when I reboot it stops forwarding to remote url again and I have to use process above. I have tried to get code to duplicate above process using cron job but no luck. Could someone please help by providing code to produce above http get e.g. .php or other. I would also like to know what this process does as it must reset something or update some data lost during reboot. Any help or suggestions welcome.

Thanks in advance.

Peter

 

 

 

 

 

 

jb79's picture

Re: 3G Forward data to remote emoncms

Hello Peter!

As I understood you've got a router connected via DSL, another connection can be done via a 3G dongle.

What's not clear for me (important to help you):

What's your exact configuration, so where is the dongle connected to? Router or somewhere else?

What do you use as base? EmonBase or RaspberrryPi, ...?

EnergyRnR's picture

Re: 3G Forward data to remote emoncms

Peter,

 just fyi - I'm trying the WR703n also, so if I can get it setup I'll try to test your scenario also (I've DSL broadband here, using OKG emonbase).... Should be ready by Thurs/Fri if I can find some time....

I have a Pi, but am not using it as a base yet.

Eamonn

PeterN's picture

Re: 3G Forward data to remote emoncms

Plan to write up when working fully and I have some spare time.

It Raspberry Pi with ready-to-go SD and  works staright away with home router.

I then configure for 3G using UMTSKeeper and Sakis3G - http://zool33.uni-graz.at/petz/umtskeeper/ and disconnect from home router. 3G connection comes up ok and I can browse internet using Huawei K3520. However every time I powercycle Raspberry pi or reboot  I have to run through above process to get it posting to remote url again. The 3G connection comes back ok each time its just that it stops posting to remote url.

 

Thanks

Peter

 

 

PeterN's picture

Re: 3G Forward data to remote emoncms

Hi Eamonn, I had a emonbase NanodeRF working with W703n and 3G dongle (K3520 and K3765) in a trial for about three months last year. For the main it worked fine but sometimes it would hand over to 2G and stop working which needed me to go to site and powercycle to rectify (I'm sure some code could sort this). The weak link was definately the wr703n connection (nanodRF just kept working), however  I really liked the wr703n with LUCI loaded, quite a nice little box. I also had wifi working for a while which was very handy. Sorry I can't add more as I moved to Raspberry Pi before testing was complete. Assume you found the site for setting up relayd but just in case http://trac.gateworks.com/wiki/relayd

You never know I may move back to NanodeRF with wr703n if things don't work out with Raspberry Pi. Anyhow I'd be interested to hear how you get on and of course if I can help I will.

Good luck

Cheers

Peter

PeterN's picture

Re: 3G Forward data to remote emoncms

Request for help from kind programmer. I need to build php script to send two lines below with short delay (a few seconds). Reason I would like to add cron job to automate process to fix issue I'm having.  Many Thanks

 

http://192.168.1.8/emoncms/raspberrypi/set?frequency=8&sgroup=210&baseid...

http://192.168.1.8/emoncms/raspberrypi/set?frequency=8&sgroup=210&baseid...

PeterN's picture

Re: 3G Forward data to remote emoncms

Tried everything but no look. Can someone please direct me to script that is invoked in my process described below and shown in attached images.

"To rectify the process used "I  have to login to dashboard Raspberry Pi and change remote url to false URL and save, then revert changes so url is correct and save again". 

For some reason this is needed to make emoncms post to remote url over 3G connection after each reboot. Once I understand process I hope to automate at boot.

Thanks in advance

Cheers

Peter

 

PeterN's picture

Re: 3G Forward data to remote emoncms

I've traced the code generated by Dashboard Raspberry Pi module during my process discussed above using wireshark. I then used code directly in internet browser and ran both HTML lines and it worked to restore posting to remote url over 3G after reboot.

First with false url

http://192.168.1.79/emoncms/raspberrypi/set?frequency=8&sgroup=210&baseid=15&remotedomain=cms.wedo.i&remoteapikey=487c485f1f0d5b9fcdb9fc4ea2ccccc

Second with correct url

 

http://192.168.1.79/emoncms/raspberrypi/set?frequency=8&sgroup=210&baseid=15&remotedomain=cms.wedo.ie&remoteapikey=487c485f1f0d5b9fcdb9fc4ea2ccccc

This means that whatever is being changed in EMONCMS by receiving above code is somehow making post to remote url work again for my 3G connection after reboot and I need to find out what code it is so I can fix or automate it.. Please note posting to remote url works fine over wifi only issue when using 3G dongle.

At this stage I'd welcome any suggestions or direction to code invoked in emoncms by above HTML lines

Cheers

Peter

 

 

 

EnergyRnR's picture

Re: 3G Forward data to remote emoncms

Peter,

 Hadn't seen relayd yet, so thanks a lot for that. Haven't made any progress since I've bricked my 703n [firmware experimentation!] and really don't want to set up a serial interface to recover it [microscopic soldering :-)] so I've ordered a new one.

While I wait I'll get the sim900 testing going again.

Eamonn.

PeterN's picture

Re: 3G Forward data to remote emoncms

Don't feel to bad I bricked one also. Tried soldering serial and gave up very quick. In all I flashed four devices several times with no issues it was only when I tried to flash with english version TL MR3020 that one bricked largely due to myself and unclear instruction  took a chance. Good Luck

Peter

PeterN's picture

Re: 3G Forward data to remote emoncms

My first attempt to automate the following process "To rectify the process used "I  have to login to dashboard Raspberry Pi and change remote url to false URL and save, then revert changes so url is correct and save again". 

First with false url

http://192.168.1.79/emoncms/raspberrypi/set?frequency=8&sgroup=210&baseid=15&remotedomain=cms.wedo.i&remoteapikey=487c485f1f0d5b9fcdb9fc4ea2ccccc

Second with correct url

 http://192.168.1.79/emoncms/raspberrypi/set?frequency=8&sgroup=210&baseid=15&remotedomain=cms.wedo.ie&remoteapikey=487c485f1f0d5b9fcdb9fc4ea2ccccc

Crontab code:

 Sudo nano /etc/crontab
*/5 * * * * root cd /var/www/emoncms/Modules/raspberrypi && php remote.php$


PHP Script:
sudo nano /var/www/emoncms/Modules/raspberrypi/remote.php

<?php


sleep (100);
$remotefalse = file_get_contents('http://192.168.1.79/emoncms/raspberrypi/set?
frequency=8&sgroup=210&baseid=15&remotedomain=cms.wedo.i&remoteapikey=
487c485f1f0d5b9fcccc$
echo $remotefalse;

sleep (30);
$remotecorrect = file_get_contents('http://192.168.1.79/emoncms/raspberrypi/set?
frequency=8&sgroup=210&baseid=15&remotedomain=cms.wedo.ie&remoteapikey=
487c485f1f0d5b9fccc$
echo $remotecorrect;
?>

Unfortunately it doesn't work. Any comments or guidence on how to check script 
or obvious errors welcome.

mharizanov's picture

Re: 3G Forward data to remote emoncms

Looks like you missed the closing quotation mark and bracket

 

$remotecorrect = file_get_contents('http://192.168.1.79/emoncms/raspberrypi/set?
frequency=8&sgroup=210&baseid=15&remotedomain=cms.wedo.ie&remoteapikey=
487c485f1f0d5b9fccc");
 

This is true for both the file_get_contents;

If that doesn't work either - you can use the same function to access remote url as used by the raspberry_run script

 

// example: getcontent($remotedomain,80,"/input/bulk.json?apikey=".$remoteapikey."&data=".$remotedata);

function getcontent($server, $port, $file)
{
   $cont = "";
   $ip = gethostbyname($server);
   $fp = fsockopen($ip, $port);
   if (!$fp)
   {
       return "Unknown";
   }
   else
   {
       $com = "GET $file HTTP/1.1\r\nAccept: */*\r\nAccept-Language: de-ch\r\nAccept-Encoding: gzip, deflate\r\nUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)\r\nHost: $server:$port\r\nConnection: Keep-Alive\r\n\r\n";
       fputs($fp, $com);
/* Don't realy need to fetch output as it slows us down
       while (!feof($fp))
       {
           $cont .= fread($fp, 500);
       }
*/
       fclose($fp);
//       $cont = substr($cont, strpos($cont, "\r\n\r\n") + 4);
//       return $cont;
   }
}

 

PeterN's picture

Re: 3G Forward data to remote emoncms

Hi Martin,

Thanks, checked and bracket is there but when I ctrl C and paste its not copied - off the screen. Here it is without node id as I don't suppose its needed.
 

<?php

sleep (100); $remotefalse =
file_get_contents('http://192.168.1.79/emoncms/raspberrypi/set?frequency=8&sgroup=210&remotedomain=cms.wedo.i&remoteapikey=487c485f1f0d5b9fcdb9fc4ea2416ac4');
echo $remotefalse;

sleep (30); $remotecorrect =
file_get_contents('http://192.168.1.79/emoncms/raspberrypi/set?frequency=8&sgroup=210&remotedomain=cms.wedo.ie&remoteapikey=487c485f1f0d5b9fcdb9fc4ea2416ac4');
echo $remotecorrect; ?>

 

The method you suggest would seem better, can you please explain how I would  add false remote url as in first case and correct remote url as in second case.

Thanks in advance.

Peter

 

mharizanov's picture

Re: 3G Forward data to remote emoncms

this showld do the trick:

 

<?php

 

getcontent("192.168.1.79",80,"/emoncms/raspberrypi/set?frequency=8&sgroup=210&remotedomain=cms.wedo.i&remoteapikey=487c485f1f0d5b9fcdb9fc4ea2416ac4");

sleep (100);

getcontent("192.168.1.79",80,"/emoncms/raspberrypi/set?frequency=8&sgroup=210&remotedomain=cms.wedo.ie&remoteapikey=487c485f1f0d5b9fcdb9fc4ea2416ac4");

 

function getcontent($server, $port, $file)
{
   $cont = "";
   $ip = gethostbyname($server);
   $fp = fsockopen($ip, $port);
   if (!$fp)
   {
       return "Unknown";
   }
   else
   {
       $com = "GET $file HTTP/1.1\r\nAccept: */*\r\nAccept-Language: de-ch\r\nAccept-Encoding: gzip, deflate\r\nUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)\r\nHost: $server:$port\r\nConnection: Keep-Alive\r\n\r\n";
       fputs($fp, $com);
/* Don't realy need to fetch output as it slows us down
       while (!feof($fp))
       {
           $cont .= fread($fp, 500);
       }
*/
       fclose($fp);
//       $cont = substr($cont, strpos($cont, "\r\n\r\n") + 4);
//       return $cont;
   }
}

?>

 

PeterN's picture

Re: 3G Forward data to remote emoncms

Hi Martin,

Many thanks, I'm trying code now and will keep you posted on progress.

Cheers

Peter

PeterN's picture

Re: 3G Forward data to remote emoncms

Hi Martin,

No luck yet file runs ok (see extract from syslog below) but unfortunately doesn't update domain Name or Write Apikey in emoncms dashboard.

Extract syslog (above code is called remote.php)

Jan 25 18:36:01 raspberrypi /USR/SBIN/CRON[29186]: (root) CMD (cd /var/www/emoncms/Modules/raspberrypi && php remote.php)
Jan 25 18:36:01 raspberrypi /USR/SBIN/CRON[29187]: (root) CMD (cd /var/www/emoncms/Modules/raspberrypi && php raspberrypi_run.php)

Will keep you posted.

Thanks

Peter

 

PeterN's picture

Re: 3G Forward data to remote emoncms

I moved new script to rc.local 

updated rc.local

root@raspberrypi:~# cat /etc/rc.local
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

# Print the IP address
exec 2> /tmp/rc.local.log  # send stderr from rc.local to a log file
exec 1>&2                      # send stdout to the same log file
set -x                         # tell sh to display commands before execution
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
  printf "My IP address is %s\n" "$_IP"
fi
/root/umtskeeper/umtskeeper --sakisoperators "USBINTERFACE='0' OTHER='USBMODEM' USBMODEM='12d1:1001'  APN='CUSTOM_APN' CUSTOM_APN='hs.vodafone.ie' APN_USER='vodafone' APN_PASS='vodafone'" --sakisswitches "--sudo --console" --devicename 'Huawei' --log --silent --monthstart 8 --nat 'no'  '/var/www/' >> /root/umtskeeper/error.log &
/etc/ && php remote.php

exit 0

 

logs

root@raspberrypi:/tmp# cat rc.local.log
+ hostname -I
+ _IP=192.168.1.7
+ [ 192.168.1.7  ]
+ printf My IP address is %s\n 192.168.1.7
My IP address is 192.168.1.7
+ /etc/
/etc/rc.local: 23: /etc/rc.local: /etc/: Permission denied
+ exit 0
+ /root/umtskeeper/umtskeeper --sakisoperators USBINTERFACE='0' OTHER='USBMODEM' USBMODEM='12d1:1001'  APN='CUSTOM_APN' CUSTOM_APN='hs.vodafone.ie' APN_USER='vodafone' APN_PASS='vodafone' --sakisswitches --sudo --console --devicename Huawei --log --silent --monthstart 8 --nat no /var/www/

 

 

PeterN's picture

Re: 3G Forward data to remote emoncms

The new remote.php is not running, I've tried manual command and no joy, I've checked raspberrypi_run.php and that runs ok which is in same directory. Any ideas? See extract from putty terminal below.

raspberrypi_run.php

root@raspberrypi:~# php /var/www/emoncms/Modules/raspberrypi/raspberrypi_run.php
Remote upload enabled - details correct
SERIAL RX: 20 189 7
SERIAL RX: 10 7 0 4 0 3 0 126 104 119 4 17 0
SERIAL RX: 20 189 7

remote.php
root@raspberrypi:~# php /var/www/emoncms/Modules/raspberrypi/remote.php        

Could not open input file: /var/www/emoncms/Modules/raspberrypi/remote.php
root@raspberrypi:~#
 

PeterN's picture

Re: 3G Forward data to remote emoncms

To test below code I called it remote.php and added it to /var/www/emoncms/Modules/raspberrypi and then run using command php remote.php. It doesn't come back with any errors but doesn't update mysql raspberrypi table with data included in getcontent below (checked using phpmyadmin).

 

Code remote.php  not working ( I'd like to add code to below to add new log file - keep you posted )

 

<?php

 

getcontent("192.168.1.7",80,"/emoncms/raspberrypi/set?frequency=8&sgroup=210&baseid=15&remotedomain=cms1.wedo.i&remoteapikey=487c485f1f0d5b9fcdb9fc4ea2416ac4");

 

getcontent("192.168.1.7",80,"/emoncms/raspberrypi/set?frequency=8&sgroup=210&baseid=15&remotedomain=cms1.wedo.ie&remoteapikey=487c485f1f0d5b9fcdb9fc4ea2416ac4");

 

function getcontent($server, $port, $file)

{

$cont = "";

$ip = gethostbyname($server);

$fp = fsockopen($ip, $port);

if (!$fp)

{

return "Unknown";

}

else

{

$com = "GET $file HTTP/1.1\r\nAccept: */*\r\nAccept-Language: de-ch\r\nAccept-Encoding: gzip, deflate\r\nUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows $

fputs($fp, $com);

/* Don't realy need to fetch output as it slows us down

while (!feof($fp))

{

$cont .= fread($fp, 500);

}

*/

fclose($fp);

// $cont = substr($cont, strpos($cont, "\r\n\r\n") + 4);

// return $cont;

}

}

?>

 

PeterN's picture

Re: 3G Forward data to remote emoncms

Call for help,

Raspberry Pi stops posting data to remote domain after reboot when using 3G dongle (note 3G connection comes up and it is possible to browse internet ok on Raspberry Pi ). As mentioned above "To rectify the process used "I  have to login to dashboard Raspberry Pi and change remote url to false URL and save, then revert changes so url is correct and save again". 

First with false url

http://192.168.1.79/emoncms/raspberrypi/set?frequency=8&sgroup=210&baseid=15&remotedomain=cms.wedo.i&remoteapikey=487c485f1f0d5b9fcdb9fc4ea2ccccc

Second with correct url

 http://192.168.1.79/emoncms/raspberrypi/set?frequency=8&sgroup=210&baseid=15&remotedomain=cms.wedo.ie&remoteapikey=487c485f1f0d5b9fcdb9fc4ea2ccccc

Here is wireshark trace file for above and screen shots of key extracts.

Wireshark_1 extract is after reboot and emoncms is not posting to remote domain.

wireshark_2 extract is after above process, note TCP starts and IP address changes now, raspberry pi starts posting to remote domain now.

wireshark_3 extract shows example of data sent

wireshark_zip is full wireshark file any needs wireshark program to open.

Any help or guidance appreciated.

Thanks

Peter

P.S. I'm using raspberry pi, with ready to go SD, sakis3g with umtskeeper and 3G K3520. Note that above is onlyt an issue for 3G, it works perfect with ethernet connection and will post to remote domain automatically after every reboot.

Thanks Martin for above code I will try get this working as temporary solution.

 

 

 

 

 

 

PeterN's picture

Re: 3G Forward data to remote emoncms

Some progress, I added Apikey of localhost to above code and it now updates post to remote domain data in localhost dashboard, tested by manually running the PHP script.  However I do need to run it several times before raspberry Pi starts posting to remote domain (after reboot).

Thanks again Martin for your help. A little closer to standalone 3G solution.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.