Using Button State on Electron to send SMS

I went ahead and began using OTA to program my particle Electron until I can find the correct device drivers. However I’m working on sending a SMS message to a Phone Number and I’m using a button State drawing the pin D0 to low using a 1K pulldown resistor. When I push the button I simply connect the 3.3V to the DO and the D7 comes on… but it doesn’t turn off for some reason. I’ve double checked the circuit and it looks correct. Here’s the code. Not sure if my brackets will be recognized when I post code but here goes.

#define MAX_PHONE_NUMBER    14
#define CTRL_Z 0x1A
#define TIMEOUT 10000

boolean gain;     // Gain setting, 0 = X1, 1 = X16;
unsigned int ms;  // Integration ("shutter") time in milliseconds
unsigned int data1;
unsigned int data2;
const int buttonPin = D0;     // the number of the pushbutton pin
const int ledPin =  D7;
int buttonState = 1; 
;  
char szPhoneNumber[MAX_PHONE_NUMBER] = "+15155055000"; //just a random phone number

int lowerLimit = 10;
boolean smsSend = false;

int callback(int type, const char* buf, int len, char* param){  
    Serial.print("Return: ");
    Serial.write((const uint8_t*)buf, len);
    Serial.println();
    
    return WAIT;
}

int setLowerLimit(String args){
    lowerLimit = args.toInt();
    
    return lowerLimit;
}

int sendMessage(char* pMessage){
    char szCmd[64];
    
    sprintf(szCmd, "AT+CMGS=\"+%s\",145\r\n", szPhoneNumber);
    
    Serial.print("Sending command ");
    Serial.print(szCmd);
    Serial.println();
    
    char szReturn[32] = "";
    
    Cellular.command(callback, szReturn, TIMEOUT, "AT+CMGF=1\r\n");
    Cellular.command(callback, szReturn, TIMEOUT, szCmd);
    Cellular.command(callback, szReturn, TIMEOUT, pMessage);
    
    sprintf(szCmd, "%c", CTRL_Z);
    
    int retVal = Cellular.command(callback, szReturn, TIMEOUT, szCmd);
    
    if(RESP_OK == retVal){
        Serial.println("+OK, Message Send");
    }
    else{
        Serial.println("+ERROR, error sending message");
    }
    
    return retVal;
}

void setup() {
    Serial.begin(115200);
    Spark.function("setmin", setLowerLimit);
      pinMode(ledPin, OUTPUT);
      pinMode(buttonPin, INPUT);
}

void loop() {
      
buttonState = digitalRead(buttonPin);

  if (buttonState == HIGH) {
    digitalWrite(ledPin, HIGH);
    Serial.println();
    Serial.println();
    char szMessage[64];
	strcpy(szMessage,  "This is Particle Electron sending Text Message test!");
	sendMessage(szMessage);
    delay(1000);
  }
  else {
    digitalWrite(ledPin, LOW);
  }
}

For one it’s not sending the text message but the LED comes on… I’ve checked the connections and its not floating a high signal either so can anyone tell me what I might be doing wrong? Thanks

I guess the SMS code you got there should work, but I know this one does work

int sendMessage(const char* telNr, const char* msg)
{
  int  ret;

  if (!strlen(telNr)) return -1;

  if (!Cellular.ready())
  {
    Cellular.on();
    Cellular.connect();
    if (!waitFor(Cellular.ready, 300000))
    {
      Log.warn("no radio connection");
      return -1;
    }
  }

  ret = Cellular.command("AT+CMGF=1\r\n");
  ret = Cellular.command("AT+CMGS=\"%s%s\",145\r\n", (telNr[0] != '+') ? "+" : "", telNr);
  ret = Cellular.command("%s\x1a", msg);
  switch (ret)
  {
    case WAIT:
      Log.info("WAITING, but probably");
    case RESP_OK:
      Log.info("Sent: '%s' to %s", msg, telNr);
      break;
    default:
      Log.warn("Message not sent (%d)", ret);
      break;
  }

  return ret;
}

But you need an SMS enabled SIM and set the APN and Particle.keepAlive() correctly

You can also try INPUT_PULLDOWN and remove your external pull-down.
And add some Serial.print() statements to show the buttonState

After hours and hours spent trying to connect up to use my USB cable to program no less than 3 separate Electrons, I can’t get two different computers to load the drivers. I’m a programmer and do lots of development. I build products with PIC microcontrollers, Arduino and Parallax and I’d like to think I’m maybe a little more informed than a beginner yet after fighting with this electron (3 of them) I’ve yet to find the drivers which allow my system to even see the serial connection. I’ve placed it in discovery mode (Flashing Blue) and I’ve installed Node.js on both computers running windows 7 which I do most of my dev and my MSDN is on. SO… WHERE ARE THE DRIVERS FOR THE ELECTRON? Can I get the drivers so I can get one of my computers to connect up to the electrons so I can program them locally? Once any of these Electrons get programmed using OTA… they freeze up… Then I try to reset them… Once reset… they do absolutely NOTHING! They’re dead! I’m frustrated to no end right now thinking I’m mentally retarded or something because I’ve yet to be able to get even ONE of these electrons to connect and run a program. WHAT THE HECK AM I DOING WRONG?