GPRS/3G For SNAP PAC remote connectivity

Hi Guys,

I’ve already tried for about a month already to get GPRS/3G going, I can do 2-way SMS using an R2 just fine and make it do what I want using SMS. But I’d like to be able to GPRS/3G directly to it (initiate a connection by SMS then it sends me its IP and disconnect it again by SMS when Im done) so I can either update its configuration (load strategy first before switching to new strategy) or even see how it is running in realtime.

Is this even possible or feasible with 3G? 3G in our area is fairly stable throughout the day so I’m sure it wont be a problem if it can be done.

edit:
I’ve tried using the GSM chart to get up and running…Instead of getting that up and running, I managed to build the web server inside Opto (without dynamic pages, yet)

We do this ‘all the time’ here in the States (In Australia, data plans are way to expensive).
Its a plug and play solution. There is no chart or software required.
Just plug your 3G modem into a router and then plug your controller into the router. Done.

If you want to do stuff like PAC Display, then set up what ever ports you need, for example, to use PAC Manager, you will need 2001. PAC Control (to download and debug) and PAC Display you will need 22001. If you want to update firmware, you will need FTP, that’s ports 20 and 21.
Since you are messing around with web page charts, you will also need port 80 (Or what ever you set up your chart to listen to).

All of this is easy to do because the Opto controller talks TCP/IP. Its the dial tone that connects the world as we know it.
(If your phone company changes your IP address of your 3G modem, use a service like dyndns to have a fixed name to address your controller, the router has a built in updater for most of the common services like that. If you chose one that is not supported, then, yeah, you will need to write a chart that sends the correct format with its real world IP address… Better to just use a router with that function built in).
If/when PAC Display disconnects from the modem, ping the domain name that you registered with dyndns, put that new IP address into PAC Terminal and this will get your connection back.
Granted, its a bit clunky, but at this stage PAC Display/Terminal can not resolve domain names.
For anything other than short term testing, you might be better to use our .net toolkit and write an app so that the modem and thus controller can be addressed via the domain name.
(With 9.1+ firmware it would be relatively straight forward to have the controller send you an email when its IP address changes, this would be a bit more pro-active, but still requires you to change the IP address in PAC Project).
I believe that in The States, At&T allocate fixed IP addresses for all GSM3 cell modems, if you are able to get connected with these guys, life would be lot easier.

Your SMS set up should not not change.

The two routers we have seen our customers using is the ‘Cradlepoint’ and ‘RavenX’.
The Cradlepoint is neat because it takes a range of USB G3 dongle modems. The Raven-X takes a sim card or is locked to your cell phone company (depends on which model you buy).

But what about if using the controller to directly manage the 3G modem via the serial port on the controller? The router + modem thing is easy, but for remote data acquisition this is going to add cost and require more space… The DynDNS part is also easy with a router (just a few clicks) compared to using the controller directly.

Would you happen to have a sample chart that uses a controller connected to a modem via serial port that uses AT Commands? There isn’t really a whole lot of information with regards to AT commands connecting to the internet…Especially not with PACs

edit: It’s also necessary for me to initiate and disconnect a 3G connection because around here, they charge PHP5/15min of air time with no so called unlimited data plan (except for really high packages).

Hey There is there a possibilty that you can supply me with the 2 way sms strategy! Its a new project that i want to try out and it would be much appretiated!!!

Hey Enzo. How’s yr optoscript? Give me a couple of weeks and ill flesh something out for you. I have some code that accepts an SMS command and responds via SMS of the result (ie fail, ok, etc…). Just it’s custom for a certain application, however same principles apply. You will need an AI for the ring indicator to alert you to an SMS.
If yr really keen, check my web app (http://22solutions.homeip.net:8080). No SMS, just straight in ovr the web. All chart based.

Thanx that will be great i got my chart up and running to sms me if any problems or alarms goes off on the system now its just to send my sms’s to the unit to return me with the info using certain predefined commands! And my rx chart is also up and running now i just need to figure out how to append the string values from my probes, meters etc. when i send the commands to the unit. And i also want to send commands via sms to stop and start equipment we have on our system. And i am using a wavecom modem with sim card plugged into the R1 serial port A. So any ideas would help and wil go check out the site now!

enzo
i know its been a little more than a couple of weeks, however i have pulled some of my code that will do a loop around a GSM modem and check for messages, grab the phone number it was sent from, the message and then perform a task based on the message. the code is optoscript and assumes a few things.
1 - com handle for the gsm modem is 'gsm_com_port’
2 - ‘sms_string_var’ is a string variable that will hold some temp strings
3 - ‘sms_return_str’ is the return string from the modem
4 - ‘sms_rx_number’ is the ph number that sent the message
5 - the modem you are using accepts standard AT commands for sms stuff
6 - your modem is configured for the correct parameters.
7 - ‘sms_control’ is the name of the chart you are using (incase we get a timeout, this chart stops and set an error variable true)


/******************************************************************************************************/
/******************************************************************************************************/
/*  this will check to see if any sms's have arrived and wether their content needs us to do anything */
/******************************************************************************************************/
/******************************************************************************************************/
SetVariableFalse(sms_received);
SetVariableFalse(sms_msg_to_send);
sms_count = 0;

/*************************************************************************************/
/*  This part makes sure that there is communication between the controller and modem*/
/*************************************************************************************/

/*  Build the 'at' string and send it */
ClearCommunicationReceiveBuffer(gsm_com_port);
sms_string_var = "at";
sms_string_var += chr(13);
sms_com_port_error = TransmitString(sms_string_var,gsm_com_port);
/*  Wait until there is an OK from the modem  */
repeat
  ReceiveString(sms_return_str, gsm_com_port);
  IncrementVariable(sms_count);
until ((FindSubstringInString("OK", 0, sms_return_str) >= 0) or (sms_count > 10));

DelayMsec(100); //this chart is a gun so we need to slow things down a bit for internal processing 

/*  if count got to 10 then there is something wrong with the communications so set the error flag and bail  */
if (sms_count > 10) then
  SetVariableTrue(sms_modem_error);
  StopChart(sms_control);
endif

  /********************************************************************************************/
  /*  now read list all the messages in the modem and delete the one we read and list them all*/
  /*  again. I know its cumbersome, but it guarantees success                                 */
  /********************************************************************************************/

/*  list all the messages in the phone  */
sms_string_var = "at+CMGL=";  //read sms at command
sms_string_var += chr(34);  //stick in the "
sms_string_var += "ALL";    //stick in the ALL
sms_string_var += chr(34);  //stick in the "
sms_string_var += chr(13);  //now for the <CR>
sms_com_port_error = TransmitString(sms_string_var,gsm_com_port); //send it down the cable

DelaySec(1); //this chart is a gun so we need to slow things down a bit for internal processing 

/*  get the string in from the buffer until we find +CMGL or OK or the loop expires  */
repeat
  IncrementVariable(sms_count); //so we don't get tied up in the loop forever
  DelayMsec(100);
  ReceiveString(sms_return_str, gsm_com_port);    
until ((FindSubstringInString("+CMGL:", 0, sms_return_str) >= 0) or (sms_count > 10) or (FindSubstringInString("OK", 0, sms_return_str) >= 0));

/*  if count got to 10 then there is something wrong with the communications so set the error flag and bail  */
if (sms_count > 10) then
  SetVariableTrue(sms_modem_error);
  StopChart(sms_control);
endif
DelayMsec(100); //this chart is a gun so we need to slow things down a bit for internal processing 

/*  if we got an ok from the modem straight up, then there are no more msg's so don't do any more */
if (FindSubstringInString("OK", 0, sms_return_str) < -1) then  //-57 means that the string was not found, so if we haven't got to an
                                                               //OK string then we haven't finished checking the list

  sms_return_str_len = GetStringLength(sms_return_str); //find out how long the string is
    
  /*  find the index number of the msg so we can delete it after we have processed it  */
  sms_return_str_srt = FindSubstringInString(" ", 0, sms_return_str); //find out where the 1st space is
  sms_return_str_end = FindSubstringInString(",", sms_return_str_srt, sms_return_str); //find out where the 1st comma is
  sms_msg_index_len = (sms_return_str_end - 1) - (sms_return_str_srt);  //this gives us the length of the string we need to read
  GetSubstring(sms_return_str, sms_return_str_srt+1, sms_msg_index_len, sms_msg_index);  //stick the index number into the var
  DelayMsec(100); //this chart is a gun so we need to slow things down a bit for internal processing 

  /*  now get the phone number the msg was sent from so we can reply if we have to */
  sms_return_str_srt = FindSubstringInString(",", 10, sms_return_str); //find out where the 2nd comma is
  sms_return_str_end = FindSubstringInString(",", sms_return_str_srt+1, sms_return_str); //find out where the 2nd comma is
  sms_return_str_len = (sms_return_str_end - 2) - (sms_return_str_srt +1);  //this gives us the length of the string we need to read
  GetSubstring(sms_return_str, sms_return_str_srt+2, sms_return_str_len, sms_rx_number); //get the phone number
        
  DelayMsec(100); //this chart is a gun so we need to slow things down a bit for internal processing 

  /*  now that we have the number,  check to see if its a number we will allow through our 'firewall' (heh, heh...) */
  //if ((FindSubstringInString("409217740", 0, sms_rx_number) >= 0) or (FindSubstringInString("400448668", 0, sms_rx_number) >= 0)) then
          
    /*  now get the sms msg */
    sms_return_str = "";    //clear the return string
                                
    ReceiveString(sms_return_str, gsm_com_port);  //read the string from the buffer
    sms_count=0;  //reset the count value
    repeat
      DelayMsec(100);
      IncrementVariable(sms_count);
    until ((GetStringLength(sms_return_str) > 1) or (sms_count > 10));

    DelayMsec(100); //this chart is a gun so we need to slow things down a bit for internal processing 
    StringToUpperCase(sms_return_str);  //convert string to uppercase to avoid confusion

    /*  now lets see if the msg has what we are looking for */

    //these next statements are where we check the string we are filtering for

    ////////////////////////////////////////////////////////////////////////////////
    //  f we find a *4320 in the string then
    //  we will then execute a command based on what we find
    
    if (FindSubstringInString("*4320", 0, sms_return_str) >= 0) then
       
      //here is where you can do findsubstringinstring and execute the command or chart required


    endif
    //
    //
    ///////////////////////////////////////////////////////////////////////////////////////
           
  //endif
      
  /*  right lets clear the buffer so we can delete the msg. I know this is a cumbersome way to do things but it ensures success */
  repeat
    ReceiveString(sms_return_str, gsm_com_port);
    //email_error_main_msg[sms_count] = sms_return_str;
    IncrementVariable(sms_count);
    DelayMsec(10);
  until ((FindSubstringInString("OK", 0, sms_return_str) >= 0) or (sms_count > 20));  
    
  ClearCommunicationReceiveBuffer(gsm_com_port);

  DelayMsec(100); //this chart is a gun so we need to slow things down a bit for internal processing 
  /*  now lets delete the msg that we just read */
  sms_count = 0;    //reset the loop counter
  sms_string_var = "at+CMGD=";  //read sms at command
  sms_string_var += sms_msg_index;
  sms_string_var += chr(13);
  sms_com_port_error = TransmitString(sms_string_var,gsm_com_port);
  DelaySec(2); //this chart is a gun so we need to slow things down a bit for internal processing
  repeat
    ReceiveString(sms_return_str, gsm_com_port);
    //email_error_main_msg[sms_count] = sms_return_str;
    IncrementVariable(sms_count);
    DelayMsec(100);
  until ((FindSubstringInString("OK", 0, sms_return_str) >= 0) or (sms_count > 10));    
        
        
  /*  if the return string is "OK" then we have got to the end of the list so get outta here */ 
  else
    SetVariableTrue(sms_receive_complete);  //when we have finished getting all the messages, then set this var true
endif


the block is executed when the RI of the modem goes greater than 3VDC, therefore RI (Pin 9 of the DB9 connector) needs to be hooked up to an AI -10 to +10VDC input.

this code has been in place for several years and has worked flawlessly (AFAIK). it could do with an overhaul, however i have not needed to therefore never have…

i hope this helps you in your quest to control via sms.
Nick

Thanks for sharing, Nick!
We have another OptoFan on LinkedIn asking what brand/model you used for this?

http://www.linkedin.com/groupAnswers?viewQuestionAndAnswers=&discussionID=276492416&gid=734807&trk=eml-anet_dig-b_nd-pst_ttle-cn&fromEmail=&ut=20E1qbwhSB0BY1

I have a similar script running and I use the Maestro evo100. Serial driven from the serial port on the R1.

Thanx nick for your input and in the meantime i got my sms problem sorted out by lot of trail & error and head scratching. So my commands i send via sms does what i want it 2 do but i had 2 include my numbers chart that sends test sms’s to the different department heads to tell them everything is working like it should but now i can use your script to reply to the person that sent the sms. So thanx for that!!! This project is still in progress and i want to expand it even more to instant messaging and already got a sample of on the site. As soon as i tidied and smoothed out my strategy i will upload it cause i recken sum other noob like me will be able to use it and Mary sorry i didn’t get back to you but i had my hands full but i still appreciate the feedback i get from all of you.

enzo
i would be keen to see what you have for IM. i have dabbled in it a bit and got something working but it required calling a php script on a web server to send the message. i never got back to doing it directly from the controller. it is all tls/ssl and even though i know the http commands can handle this, i just didn’t get any time to give it a go. heres the link to the forum thread
http://www.opto22.com/community/showthread.php?t=245
it may help you with your development

mary,
i developed the script on a sony GT47 modem and the same chart imported and ‘just worked’ on an Intercel SAM2W.

Yes that is my next step that i want to do i got a im script on the site just have to juggle around with it also want to know if any1 has tried or fiddled with a usb modem to work directly with controller

Wishing we had a “like” button I could click here!!

Ha ha that could work its now only 2 months which i am into automation and started opto and each day is getting more exciting and even more exciting is that our groove unit is ariving sumtime this week so christmas came early!!! :slight_smile: :slight_smile: :slight_smile: