Low memory available, stability problems may occur

Bluetooth, XBee, RF......

Low memory available, stability problems may occur

Postby kelvinswee94 » Wed Mar 28, 2018 5:32 pm

Hi, I am using Cytron Uno to connect LoRa RFM shield and Espresso Lite V2.0 to upload incoming data to web server.

Here is my code:
CODE: SELECT_ALL_CODE
#include <CytronWiFiShield.h>
#include <CytronWiFiClient.h>
#include <SoftwareSerial.h>
#include <ThingSpeak.h>
#include <WiFi.h>
#include <SPI.h>
#include <RH_RF95.h>
const char *ssid = "myasus";
const char *pass = "sweeswee";
char thingSpeakAddress[] = "api.thingspeak.com";
String APIKey = "0KQX3E5NLZRYIYJM";
const int updateThingSpeakInterval;     
ESP8266Client client;
WiFiServer server(80);
long lastConnectionTime = 0;
boolean lastConnected = false;
#define RFM95_CS 10
#define RFM95_RST 7
#define RFM95_INT 2
#define RF95_FREQ 915.0
RH_RF95 rf95(RFM95_CS, RFM95_INT);                     
void setup() {
// put your setup code here, to run once:
  pinMode(RFM95_RST, OUTPUT);
  digitalWrite(RFM95_RST, HIGH);
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }
  if(!wifi.begin(8, 9))
  {
    Serial.println(F("Error talking to shield"));
    while(1);
  }
  Serial.println(F("Start wifi connection"));
  if(!wifi.connectAP(ssid, pass))
  {
    Serial.println(F("Error connecting to WiFi"));
    while(1);
  }
  Serial.print(F("Connected to "));Serial.println(wifi.SSID());
  Serial.println(F("IP address: "));
  Serial.println(wifi.localIP());
  ThingSpeak.begin(client);
  delay(1000);
  Serial.println(F("LoRa Receiver"));
  digitalWrite(RFM95_RST, LOW);
  delay(10);
  digitalWrite(RFM95_RST, HIGH);
  delay(10);
  while (!rf95.init()) {
    Serial.println(F("LoRa radio init failed"));
    while (1);
  }
  Serial.println(F("LoRa radio init OK!"));
  if (!rf95.setFrequency(RF95_FREQ)) {
    Serial.println(F("setFreq failed"));
    while (1);
  }
  Serial.print(F("Set Freq to: ")); Serial.println(RF95_FREQ);


}
void loop() {

  String distance = (F("11")); // read light value
  String help = (F("14"));

  // Print Update Response to Serial Monitor
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }
  // Disconnect from ThingSpeak
  if (!client.connected() && lastConnected) {
    Serial.println(F("disconnected"));
    Serial.println();
    client.stop();
  }
  // Update ThingSpeak
  if (!client.connected() && (millis() - lastConnectionTime > updateThingSpeakInterval)) {
    updateThingSpeak("field1=" + distance + "&field2=" + help);
    Serial.println(distance);
    Serial.println(help);

  }
  lastConnected = client.connected();
 
}

void updateThingSpeak(String tsData) {
  if (client.connect(thingSpeakAddress, 80)) {
    client.print("POST /update HTTP/1.1\n");
    client.print("Host: api.thingspeak.com\n");
    client.print("Connection: close\n");
    client.print("X-THINGSPEAKAPIKEY: " + APIKey + "\n");
    client.print("Content-Type: application/x-www-form-urlencoded\n");
    client.print("Content-Length: ");
    client.print(tsData.length());
    client.print("\n\n");
    client.print(tsData);
    lastConnectionTime = millis();

    if (client.connected()) {
      Serial.println(F("Connecting to ThingSpeak..."));
      Serial.println();
    }
  }
}


However i encounter this issue
"Low memory available, stability problems may occur"
Is there anyway i can reduce the memory use? Thanks
kelvinswee94
Novice
 
Posts: 16
Joined: Wed Nov 15, 2017 4:19 pm

Return to Wireless Device

Who is online

Users browsing this forum: No registered users and 10 guests

cron