Jump to content
43oh

Ssherry

Members
  • Content Count

    1
  • Joined

  • Last visited

Posts posted by Ssherry

  1. I am working on code related to sending an email through cc3100booster and msp432p401r. I am having an issue in connectivity of wifi in the module when the wifi connection code is provided in void setup(). I am providing mobile's hotspot and it gets connected and disconnected periodically. I require an continuous connection.

    When the wifi connection code is written inside loop(), the connection problem is solved but a newer issue is arised i,e, the program is running for email but not for the server [In server program i am sending temperature and pulse count value to thingspeak.com to get a graphical representation of my data.]

    moreover, despite of being present in loop, it executes only once. its a complete arcane issue for me. I am linking code below. please help me out with this.

    #define TEMBOO_ACCOUNT "xxxxxxx"  // your Temboo account name
    #define TEMBOO_APP_KEY_NAME "xxxxxxx"  // your Temboo app name
    #define TEMBOO_APP_KEY  "xxxxxxxx"  // your Temboo app key
     
    #define WIFI_SSID "xxxxxx"   //hotspot name
    #define WIFI_PASSWORD "xxxxxxx"   //hotspot password
    #ifndef __CC3200R1M1RGC__
    #include <SPI.h>
    #include <WiFi.h>
    #include <WiFiClient.h>
    #include <Temboo.h>
    #endif
     
     
    const String GMAIL_USER_NAME = "xxxxxxx"; //sender's email
     
    const String GMAIL_APP_PASSWORD = "xxxxxx" //sender's app password
     
    const String TO_EMAIL_ADDRESS = "xxxxxxx";    //receiver's email
     
    boolean attempted = false;
     
    #include <LiquidCrystal.h>
    LiquidCrystal lcd(13,33,12,24,5,25,6,26,27,8,28);
     
      float temp;
      float volt;
      int sensorValue1;
      int sensorValue2;
      int count;
    WiFiClient client;
     
    char server[] = "api.thingspeak.com";
    unsigned long lastConnectionTime = 0;            // last time you connected to the server, in milliseconds
    const unsigned long postingInterval = 10L * 1000L; // delay between updates, in milliseconds
     
    void checkconnection()
    {
      int wifiStatus = WL_IDLE_STATUS;
     
      // determine if the WiFi Shield is present.
      Serial.print("\n\nShield:");
      
        
      if (WiFi.status() == WL_NO_SHIELD) {
       
        Serial.println("FAIL");
       
        
        // if there's no WiFi shield, stop here.
        while(true);
      }
        
      while(wifiStatus != WL_CONNECTED) {
        Serial.print("WiFi:");
        wifiStatus = WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
     
        if (wifiStatus == WL_CONNECTED) {
          Serial.println("OK");
        } else {
          Serial.println("FAIL");
        }
        delay(1000);
      }
       Serial.println("Waiting for an ip address");
      
      while (WiFi.localIP() == INADDR_NONE) {
        // print dots while we wait for an ip addresss
        Serial.print(".");
        delay(300);
      }
     
      Serial.println("\nIP Address obtained");
      // We are connected and have an IP address.
      // Print the WiFi status.
      printWifiStatus();
    }
     
    void serverprog()
    {
     while (client.available()) {
        char c = client.read();
        Serial.write(c);
      
     if (millis() - lastConnectionTime > postingInterval) {
        httpRequest();
      }
    }
     
     
     
    void httpRequest() {
      // close any connection before send a new request.
      // This will free the socket on the WiFi shield
      client.stop();
     
      // if there's a successful connection:
      if (client.connect(server, 80)) {
        Serial.println("connecting...");
        char msgg[200];
        sprintf(msgg,"GET /update?api_key=xxxxxxxxxxxxxxxx&field1=%f&field2=%d",temp,count);  //have to make account on thingspeak.com and create channel then create 2 fields. then copy the WRITE API key in place of xxxxxxxxx
        // send the HTTP PUT request:
        client.println(msgg);
        client.println("Host: api.thingspeak.com");
        client.println("User-Agent: Energia/1.1");
        client.println("Connection: close");
        client.println();
     
        // note the time that the connection was made:
        lastConnectionTime = millis();
      }
      else {
        // if you couldn't make a connection:
        Serial.println("connection failed");
      }
    }
     
     
    void printWifiStatus() {
      // print the SSID of the network you're attached to:
      Serial.print("SSID: ");
      Serial.println(WiFi.SSID());
     
      // print your WiFi IP address:
      IPAddress ip = WiFi.localIP();
      Serial.print("IP Address: ");
      Serial.println(ip);
     
      // print the received signal strength:
      long rssi = WiFi.RSSI();
      Serial.print("signal strength (RSSI):");
      Serial.print(rssi);
      Serial.println(" dBm");
    }
     
     
       void setup() {
      lcd.begin(16, 2);
     
      Serial.begin(9600);
      Serial.println("processing......");
      
     
     
       }
     
     
     
    void loop() {
      int sensorValue1 = analogRead(A0);
      lcd.clear();
        lcd.setCursor(0,2);
      lcd.print("wait..");
     /* lcd.setCursor(0,0);
      lcd.print("temperature =");
      lcd.setCursor(14,0);
      lcd.print(temp);*/
       
      Serial.println(sensorValue1);
      volt=sensorValue1*3.22;
      temp=volt/10;
      Serial.println(volt);
      Serial.println("temp=");
      Serial.println(temp);
      delay(10);
      
     int sensorValue2;
      unsigned long start=millis();
      analogReadResolution(10);
      unsigned long currentValue;
      float x=0;
      int y;
      count=0;
      delay(3000);
      lcd.clear();
     
    lcd.setCursor(0,2);
    lcd.print("detecting.......");
      do
      {
        int sensorValue2 = analogRead(A1);
        if(sensorValue2 > x)
       
        {
          x=sensorValue2;
          y=1;
         
        }
    else if(sensorValue2 < x)
     
    {
       x=sensorValue2;
       if(y==1)
       {
         count++;
         y=0;
       }
    }
     
    currentValue=millis();
      }
      while(currentValue-start<=30000);
       count=(count*2)/10000;
      lcd.clear();
      lcd.setCursor(0,0);
     lcd.print("temperature =");
      lcd.setCursor(14,0);
      lcd.print(temp);
       lcd.setCursor(0,2);
      lcd.print("pulse count =");
      lcd.setCursor(14,1);
        lcd.print(count);
        delay(1000);
     
         
      Serial.println(sensorValue2);
       Serial.println("pulse count=");
        Serial.println(count);
        checkconnection();
        delay(3000);
        
      if (!attempted) {
       
        Serial.println("Running SendAnEmail...");
      
        TembooChoreo SendEmailChoreo(client);
     
        SendEmailChoreo.begin();
        
        SendEmailChoreo.setAccountName(TEMBOO_ACCOUNT);
        SendEmailChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
        SendEmailChoreo.setAppKey(TEMBOO_APP_KEY);
        SendEmailChoreo.setChoreo("/Library/Google/Gmail/SendEmail");
     
        SendEmailChoreo.addInput("Username", GMAIL_USER_NAME);
       
        SendEmailChoreo.addInput("Password", GMAIL_APP_PASSWORD);
        SendEmailChoreo.addInput("ToAddress", TO_EMAIL_ADDRESS);
      
        SendEmailChoreo.addInput("Subject", "Recieved An Email???");
      char msg[100];
      sprintf (msg," Body Temperature=%f, Pulse count=%d",temp,count);
        SendEmailChoreo.addInput("MessageBody", msg);
     
           unsigned int returnCode = SendEmailChoreo.run();
     
        if (returnCode == 0) {
            Serial.println("Success! Email sent!");
        } else {
               while (SendEmailChoreo.available()) {
            char c = SendEmailChoreo.read();
            Serial.print(c);
          }
        }
        SendEmailChoreo.close();
        
      }
     serverprog();
         lcd.clear();
     
    }
×
×
  • Create New...