Facebook
From Nana, 4 Years ago, written in C.
This paste is a reply to Untitled from cbproyectos - view diff
Embed
Download Paste or View Raw
Hits: 223
  1.  
  2. [code]//#include <SoftwareSerial.h>
  3.  
  4. #define RxNodePin 3
  5. #define TxNodePin 2
  6.  
  7. uint8_t temperatura[12]={1};
  8. uint8_t sigfoxMsg[12];
  9. uint8_t temp[12]={1};
  10. //SoftwareSerial Sigfox(RxNodePin, TxNodePin);
  11. //
  12. void setup() {
  13.   Serial.begin(115200);
  14.   delay(300);
  15.   Serial.print("Device ID: " + getID());
  16.   Serial.print("Device PAC Number: " + getPAC());
  17.   delay(100);
  18. }
  19.  
  20. void loop() {
  21.  memcpy(sigfoxMsg, &temperatura, sizeof(temperatura));
  22.  Serial.print(sendMessage(tempura, 8));
  23. }
  24.  
  25. String getID () {
  26.   String deviceId = "";
  27.   char sigfoxBuffer;
  28.   Serial.print("AT$I=10\r");
  29.   while (!Serial.available()){
  30.      delay(20);
  31.   }
  32.  
  33.   while(Serial.available()){
  34.     sigfoxBuffer = Serial.read();
  35.     deviceId += sigfoxBuffer;
  36.     delay(20);
  37.   }
  38.   return deviceId;
  39. }
  40.  
  41. String getPAC (){
  42.   String pacNumber = "";
  43.   char sigfoxBuffer;
  44.  
  45.   // to WISOL to GET PAC number
  46.   Serial.print("AT$I=11\r");
  47.   while (!Serial.available()){
  48.      delay(10);
  49.   }
  50.   while(Serial.available()){
  51.     sigfoxBuffer = Serial.read();
  52.     pacNumber += sigfoxBuffer;
  53.     delay(10);
  54.   }
  55.   return pacNumber;
  56. }
  57.  
  58. String sendMessage(uint8_t sigfoxMsg[], int bufferSize) {
  59.   String status = "";
  60.   char sigfoxBuffer;
  61.  
  62.   Serial.print("AT$SF=");
  63.   for(int i= 0;i<bufferSize;i++){
  64.    
  65.     if (sigfoxMsg[i]<0x10)
  66.     {
  67.      Serial.print("0");
  68.     }
  69.     Serial.print(String(sigfoxMsg[i], HEX));
  70.   }
  71.  
  72.  Serial.print("\r");
  73.  
  74.   while (!Serial.available()){
  75.      delay(10);
  76.   }
  77.  
  78.   while(Serial.available()){
  79.     sigfoxBuffer = (char)Serial.read();
  80.     status += sigfoxBuffer;
  81.     delay(10);
  82.   }
  83.  
  84.   return status;
  85. }[/code]