42 lines
988 B
Go
42 lines
988 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"io/ioutil"
|
|
"log"
|
|
"time"
|
|
"net/http"
|
|
"net/url"
|
|
)
|
|
|
|
func sendSMS(phonenumber string, alertMessage string) {
|
|
myurl := fmt.Sprintf("https://api.smsapi.com/sms.do?to=%s&message=%s&format=json",phonenumber,url.QueryEscape(alertMessage))
|
|
|
|
req, err := http.NewRequest("GET", myurl, nil)
|
|
if err != nil {
|
|
log.Fatal("Error reading request. ", err)
|
|
}
|
|
|
|
req.Header.Set("Authorization", "Bearer IQ4vRG2JvNOmYmrYz6RuSwAanYZgd2hHGwtN62kq")
|
|
|
|
client := &http.Client{Timeout: time.Second * 10}
|
|
|
|
resp, err := client.Do(req)
|
|
if err != nil {
|
|
log.Fatal("Error reading response. ", err)
|
|
}
|
|
defer resp.Body.Close()
|
|
|
|
body, err := ioutil.ReadAll(resp.Body)
|
|
if err != nil {
|
|
log.Fatal("Error reading body. ", err)
|
|
}
|
|
|
|
fmt.Printf("%s\n", body)
|
|
}
|
|
|
|
func sendAlert(deveui string, alertMessage string) {
|
|
fmt.Printf("sendAlert: deveui=%s, message=%s\n", deveui, alertMessage)
|
|
sendSMS("41765006123",alertMessage)
|
|
}
|