Skip to content

Instantly share code, notes, and snippets.

@ToeJamson
Created February 13, 2015 20:27
Show Gist options
  • Save ToeJamson/5c18c6b5d6f4fc7b9f95 to your computer and use it in GitHub Desktop.
Save ToeJamson/5c18c6b5d6f4fc7b9f95 to your computer and use it in GitHub Desktop.
void loop(){
if(gprs.available()){
Serial.write(gprs.read());
}
if(Serial.available()){
gprs.write(Serial.read());
}
}
http://pubsub.pubnub.com
/publish
/pub-key
/sub-key
/signature
/channel
/callback
/message
RDY
+CFUN: 1
+CPIN: READY
+PACSP: 0
Call Ready
ATD1***8675309;
GPRS gprs(PIN_TX, PIN_RX, BAUDRATE,"cmnet");
GPRS(int tx, int rx, uint32_t baudRate = 9600, const char* apn = NULL, const char* userName = NULL, const char *passWord = NULL);
GPRS gprs(PIN_TX, PIN_RX, BAUDRATE, "wap.cingular", "WAP@CINGULARGPRS.COM", "CINGULAR1");
#include <GPRS_Shield_Arduino.h>
#include <SoftwareSerial.h>
#include <Wire.h>
#include <Suli.h>
#define PIN_TX 7
#define PIN_RX 8
//make sure that the baud rate of SIM900 is 9600!
//you can use the AT Command(AT+IPR=9600) to set it through SerialDebug
#define BAUDRATE 9600
GPRS gprs(PIN_TX, PIN_RX, BAUDRATE, "wap.cingular", "WAP@CINGULARGPRS.COM", "CINGULAR1");
void publishData(String data) {
Serial.println("attempting to publish");
while (false == gprs.join()) {
Serial.println("gprs join network error");
delay(2000);
}
String str = "GET /publish/demo/demo/0/pubnub_gprs/0/\"" + data + "\" HTTP/1.0\r\n\r\n";
// Length (with one extra character for the null terminator)
int str_len = str.length() + 1;
// Prepare the character array (the buffer)
char http_cmd[str_len];
// Copy it over
str.toCharArray(http_cmd, str_len);
char buffer[512];
if (false == gprs.connect(TCP, "pubsub.pubnub.com", 80)) {
Serial.println("connect error");
} else {
Serial.println("publish success");
Serial.println(data);
}
gprs.send(http_cmd, sizeof(http_cmd) - 1);
gprs.close();
}
int counter = 0;
void setup() {
Serial.println("starting");
Serial.begin(9600);
// use DHCP
gprs.init();
// attempt DHCP
while(true){
publishData(String(counter));
counter++;
delay(1000);
}
gprs.disconnect();
}
void loop() {
}
String str = "GET /publish/demo/demo/0/pubnub_gprs/0/\"" + data + "\" HTTP/1.0\r\n\r\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment