SMS example

SMS example

SMS_example
#include <io> #include <read> #include <float> #include <string> #include <core> #include <write> #include <define> new ignition_state; // Variable new last_ignition_state = 0; // Variable new sms_text[100]; // Array new number[15]; // Array public callback (sk) { switch(sk) { case SMS: // If SMS callback event { ReadSMS(); // Go to ReadSMS() function } } return 0; } ReadSMS() // ReadSMS function { read_buf(SMStext, 99, sms_text); // Read SMS text to sms_text[] array read_buf(PhoneNumber, 14, number); // Read phone number to number[] array if(strcmp(sms_text, "Input5?", false, 7)==0){ // Check SMS text if it is "Input5?" do... if (get_val(Sensor_SignalIN5) == 1) // Get input 5 value if it equal 1 do... write_buf(SMS, 0, number, "IN5 status ON"); // Send SMS back to number with "IN5 status ON" message else // if input 5 value not equal 1 do... write_buf(SMS, 0, number, "IN5 status OFF"); // Send SMS back to number with "IN5 status OFF" message } else // if SMS text not equal "Input5?" do... { write_buf(SMS, 0, number, "Error"); // Send SMS back to number with "Error" message } } main() { write_buf(SMS, 0, "+370611111XX", "Device started..."); // Send SMS to "+370611111XX" with "Device started..." message Delay(4000); // Delay 4 sec. last_ignition_state = get_val(Sensor_SignalIN5); // Get ignition status from input 5 and Assign it to last ignition state while (1) { ignition_state = get_val(Sensor_SignalIN5); // Get ignition status from input 5 if (ignition_state != last_ignition_state) // if ignition state not equal last ignition state do... { if (ignition_state == 1) // if ignition state equal 1 do... { write_buf(SMS, 0, "+370611111XX", "Ignition: on"); // Send SMS to "+370611111XX" with "Ignition: on" message last_ignition_state = ignition_state; // Assign ignition state to last ignition state } else if (ignition_state == 0) { write_buf(SMS, 0, "+370611111XX", "Ignition off"); // Send SMS to "+370611111XX" with "Ignition: off" message last_ignition_state = ignition_state; // Assign ignition state to last ignition state } } Delay(100); // Delay 100 ms } }