Error using thingspeak talk back to control arduino led - arduino

The error I'm facing is about using talkback function of thingspeak to control my Arduino LED. it cannot execute the talkback command to off the led. The error is in my void get talkback. Please help me
#include "ThingSpeak.h"
#include <Ethernet.h>
#define redLED 8
byte mac[] = {0x90, 0xA2, 0xDA, 0x10, 0x40, 0x4F};
const String channelsAPIKey = "";
const String talkBackAPIKey = "";
const String talkBackID = "";
const String talkCommandID = "";
const unsigned int getTalkBackInterval = 10 * 1000;
const unsigned int updateChannelsInterval = 15 * 1000;
String talkBackCommand;
long lastConnectionTimeChannels = 0;
boolean lastConnectedChannels = false;
int failedCounterChannels = 0;
long lastConnectionTimeTalkBack = 0;
boolean lastConnectedTalkBack = false;
int failedCounterTalkBack = 0;
char charIn;
// Arduino Ethernet Client is initialized
EthernetClient client;
void setup()
{
Ethernet.init(10); // Most Arduino Ethernet hardware
Serial.begin(9600); //Initialize serial
// start the Ethernet connection:
pinMode(redLED, OUTPUT);
digitalWrite(redLED, HIGH);
}
void loop()
{
getTalkBack();
}
void getTalkBack()
{
String tsData;
tsData = talkBackID + "/commands/execute?api_key=" + talkBackAPIKey;
if ((!client.connected() && (millis() - lastConnectionTimeTalkBack > getTalkBackInterval)))
{
if (client.connect("api.thingspeak.com", 80))
{
client.println("GET /talkbacks/" + tsData + " HTTP/1.0");
client.println();
lastConnectionTimeTalkBack = millis();
if (client.connected())
{
Serial.println("---------------------------------------");
Serial.println("GET TalkBack command");
Serial.println();
Serial.println("Connecting to ThingSpeak");
Serial.println();
Serial.println();
Serial.println("Server response");
Serial.println();
failedCounterTalkBack = 0;
while (client.connected() && !client.available()) delay(2000); //waits for data
while (client.connected() || client.available())
{
charIn = client.read();
talkBackCommand += charIn;
Serial.print(charIn);
if (talkBackCommand == "LED_ON")
{
digitalWrite(redLED, HIGH);
}
if (talkBackCommand == "LED_OFF")
{
digitalWrite(redLED, LOW);
}
}
if (talkBackCommand = talkBackCommand.substring(talkBackCommand.indexOf("_CMD_") + 5));
{
Serial.println();
Serial.println();
Serial.println("Disconnected");
Serial.println();
Serial.println("--------");
Serial.println();
Serial.println("talkback command was");
Serial.println();
Serial.println("--------");
Serial.println();
Serial.println(talkBackCommand);
Serial.println("--------");
Serial.println();
}
}
else
{
failedCounterTalkBack++;
Serial.println("Connection to ThingSpeak failed (" + String(failedCounterTalkBack, DEC) + ")");
Serial.println();
lastConnectionTimeChannels = millis();
}
}
}
if (failedCounterTalkBack > 3 )
{
startEthernet();
}
client.stop();
Serial.flush();
}
The below is a image from my serial monitor. It shows that I can capture the command but couldn't execute it.

Looks like you are reading and appending all the received bytes to talkBackCommand. So, talkBackCommand is "HTTP/1.1 200 OK Date...." and if (talkBackCommand == "LED_ON") would never be true.
I think you wanted to see if the received data contain your commands LED_ON or LED_OFF. You can do something like this:
if (talkBackCommand.indexOf("LED_ON") != -1)
indexOf() locates a String in a String and returns index or -1 if not found.
See more info about indexOf() here: https://www.arduino.cc/reference/en/language/variables/data-types/string/functions/indexof/

Related

I am having trouble sending data to website from ESP8266 (ESP-01) via Arduino with AT commands

I am sending GET request to my website via the ESP8266 through Arduino AT commands.
I have searched a lot on Google but couldn't come up with a good solution.
For the first loop the code works fine but for next loop the code gives errors.
Different type
Here is my code:
#include <SoftwareSerial.h>
SoftwareSerial esp(2, 3); // Arduino RX:2, TX:3
String WIFI_SSID = "wifi_ssid"; //your network SSID
String WIFI_PWD = "wifi_pass"; //your network password
String Domain = "www.example.com";
void setup() {
Serial.begin(9600);
Serial.println("Started....");
esp.begin(9600);
//esp.setTimeout(500);
espAT("AT\r\n", 1000);
espAT("AT+CWMODE=1\r\n", 1000);
espAT("AT+CWJAP=\"" + WIFI_SSID + "\",\"" + WIFI_PWD + "\"\r\n", 5000);
espAT("AT+CIPSTATUS\r\n", 1000);
espAT("AT+CIPSTART=\"TCP\",\"" + Domain + "\",80\r\n", 5000);
}
void loop() {
int val = rand() % 255;
String request = "GET /iot/ HTTP/1.1\r\nHost: " + Domain + "\r\n\r\n";
espAT("AT\r\n", 1000);
espAT("AT+CIPSEND=" + String(request.length()+2) + "\r\n", 500);
espAT(request, 200);
String response = "";
while (esp.available()) {
response = esp.readStringUntil('0');
}
Serial.println(response);
espAT("AT+CIPCLOSE\r\n", 0);
delay(5000);
}
void espAT(String command, int waitFor)
{
esp.print(command);
int timeMillis = millis() + waitFor;
while (timeMillis > millis()) {
if (esp.available()) {
Serial.write(esp.read());
}
}
}
This code here in this instructable works for me quiet efficiently.
#include <SoftwareSerial.h>
String ssid ="yourSSID";
String password="yourPassword";
SoftwareSerial esp(6, 7);// RX, TX
String data;
String server = "yourServer"; // www.example.com
String uri = "yourURI";// our example is /esppost.php
int DHpin = 8;//sensor pin
byte dat [5];
String temp ,hum;
void setup() {
pinMode (DHpin, OUTPUT);
esp.begin(9600);
Serial.begin(9600);
reset();
connectWifi();
}
//reset the esp8266 module
void reset() {
esp.println("AT+RST");
delay(1000);
if(esp.find("OK") ) Serial.println("Module Reset");
}
//connect to your wifi network
void connectWifi() {
String cmd = "AT+CWJAP=\"" +ssid+"\",\"" + password + "\"";
esp.println(cmd);
delay(4000);
if(esp.find("OK")) {
Serial.println("Connected!");
}
else {
connectWifi();
Serial.println("Cannot connect to wifi"); }
}
byte read_data () {
byte data;
for (int i = 0; i < 8; i ++) {
if (digitalRead (DHpin) == LOW) {
while (digitalRead (DHpin) == LOW); // wait for 50us
delayMicroseconds (30); // determine the duration of the high level to determine the data is '0 'or '1'
if (digitalRead (DHpin) == HIGH)
data |= (1 << (7-i)); // high front and low in the post
while (digitalRead (DHpin) == HIGH);
// data '1 ', wait for the next one receiver
}
} return data; }
void start_test () {
digitalWrite (DHpin, LOW); // bus down, send start signal
delay (30); // delay greater than 18ms, so DHT11 start signal can be detected
digitalWrite (DHpin, HIGH);
delayMicroseconds (40); // Wait for DHT11 response
pinMode (DHpin, INPUT);
while (digitalRead (DHpin) == HIGH);
delayMicroseconds (80);
// DHT11 response, pulled the bus 80us
if (digitalRead (DHpin) == LOW);
delayMicroseconds (80);
// DHT11 80us after the bus pulled to start sending data
for (int i = 0; i < 4; i ++)
// receive temperature and humidity data, the parity bit is not considered
dat[i] = read_data ();
pinMode (DHpin, OUTPUT);
digitalWrite (DHpin, HIGH);
// send data once after releasing the bus, wait for the host to open the next Start signal
}
void loop () {
start_test ();
// convert the bit data to string form
hum = String(dat[0]);
temp= String(dat[2]);
data = "temperature=" + temp + "&humidity=" + hum;// data sent must be under this form //name1=value1&name2=value2.
httppost();
delay(1000);
}
void httppost () {
esp.println("AT+CIPSTART=\"TCP\",\"" + server + "\",80");//start a TCP connection.
if( esp.find("OK")) {
Serial.println("TCP connection ready");
} delay(1000);
String postRequest =
"POST " + uri + " HTTP/1.0\r\n" +
"Host: " + server + "\r\n" +
"Accept: *" + "/" + "*\r\n" +
"Content-Length: " + data.length() + "\r\n" +
"Content-Type: application/x-www-form-urlencoded\r\n" +
"\r\n" + data;
String sendCmd = "AT+CIPSEND=";//determine the number of caracters to be sent.
esp.print(sendCmd);
esp.println(postRequest.length() );
delay(500);
if(esp.find(">")) { Serial.println("Sending.."); esp.print(postRequest);
if( esp.find("SEND OK")) { Serial.println("Packet sent");
while (esp.available()) {
String tmpResp = esp.readString();
Serial.println(tmpResp);
}
// close the connection
esp.println("AT+CIPCLOSE");
}
}}
ESP8266 using the Arduino community firmware is as good as an Arduino. I propose to use the ESP8266 and should you need the Arduino, have them communicate using serial. It seems neater.
Best,
Odysseas

Sending and receiving sms with arduino, using sim900

I have a strange problem with my project. I am able to send and receive SMS messages but for some reason not from the same project.
This little one sends a message, and is working properly:
#include <SoftwareSerial.h>
SoftwareSerial SIM900(7, 8);
String no = "+38762701893";
String message = "this is some message";
void setup() {
SIM900.begin(19200);
delay(20000);
}
void sendSMS(String number, String mess) {
SIM900.print("AT+CMGF=1\r");
delay(100);
SIM900.println("AT + CMGS = \"" + number + "\"");
delay(100);
SIM900.println(mess);
delay(100);
SIM900.println((char)26);
delay(100);
SIM900.println();
delay(5000);
}
void loop() {
sendSMS(no, message);
do {} while (1);
}
However, if I want this same function to work under a little bigger program which receives SMS messages and responds to them, it doesn't work.
This is the complete code of the not working example:
#include <SoftwareSerial.h>
SoftwareSerial SIM900(7, 8);
String no = "+122333444"; //phone number
String message = "";
char inchar;
int b = 13;
bool state = 0;
void setup()
{
Serial.begin(19200);
SIM900.begin(19200);
delay(5000);
SIM900.print("AT+CMGF=1\r");
delay(100);
SIM900.print("AT+CNMI=2,2,0,0,0\r");
delay(100);
Serial.println("Ready...");
SIM900.begin(19200);
delay(500);
pinMode(b, OUTPUT);
}
void sendSMS(String number, String mess) {
SIM900.print("AT+CMGF=1\r");
delay(200);
SIM900.println("AT+CMGS=\"" + number + "\"");
delay(100);
SIM900.println(mess);
delay(100);
SIM900.println((char)26);
delay(100);
SIM900.println();
delay(8000);
}
void loop()
{
if (state) {
sendSMS(no, message);
state = 0;
}
if (SIM900.available() > 0) {
inchar = SIM900.read();
Serial.print(inchar);
if (inchar == '#') {
delay(10);
inchar = SIM900.read();
Serial.print(inchar);
if (inchar == 'a') {
delay(10);
inchar = SIM900.read();
Serial.print(inchar);
if (inchar == '0') {
digitalWrite(b, LOW);
message = "something is off";
} else if (inchar == '1') {
digitalWrite(b, HIGH);
message = "something is on";
}
}
state = 1;
}
}
}
This program receives the SMS, turns on the LED, or turns it off, depending of the SMS content, but it won't reply for some reason. Any help is greatly appreciated.
Your code for sending SMS is incorrect.I would suggest using a library like gsmlib for arduino it will handle all the tasks appropriately.
Firstly
SIM900.print("AT+CMGF=1\r");
This should be done once in setup().
After sending SIM900.println("AT+CMGS=\"" + number + "\""); you need to wait for the modem to respond with > after which you can send the text. In your case you are assuming that the modem would have sent it within 200ms.
There are several gsm libs available where you can just use a function like sendSMS(number,text) and it will handle all the other stuff.
I did that in C#, but you can convert to Arduino easily:
private void sendSMS_GSM()
{
if (serialPort.IsOpen)
{
strResponseSim = "";
serialPort.WriteLine("AT+CMGF=1\r\n");
while (strResponseSim != "AT+CMGF=1\r\r\nOK\r\n") ;
strResponseSim = "";
serialPort.WriteLine("AT+CSCS=\"GSM\"\r\n");
while (strResponseSim != "AT+CSCS=\"GSM\"\r\r\nOK\r\n") ;
strResponseSim = "";
serialPort.WriteLine("AT+CMGS=\"" + txtPhone.Text + "\"\r\n");
serialPort.WriteLine(txtMessage.Text);
serialPort.Write(new byte[] { 26 }, 0, 1);
while (strResponseSim == "OK") ;
strResponseSim = "";
}
}

Hold button more than 5 seconds, do something. Arduino

I have a hobby project that sends a string "1" or a string "0" to my webserver. My arduino work as a client, and It works, but now I want to add another statement.
If the button is held down 5 sec or longer, send string "5" to my webserver. I do not know how I can get the button to count the seconds I have hold the button. Can you please help?
Here is the code:
#include <SPI.h>
#include <WiFi.h>
byte mac[] = { 0xDE, 0xFD, 0xBE, 0xEF, 0xFE, 0xED }; // MAC adresse
char ssid[] = "test";
char pass[] = "123456789";
IPAddress ip(192, 168, 0, 143); // Klient IP
IPAddress server(192,168,0,100); // Server IP
int port = 2056;
boolean btnpressed = false;
int status = WL_IDLE_STATUS;
WiFiClient client;
unsigned long lastConnectionTime = 0;
boolean lastConnected = false;
const unsigned long postingInterval = 1000;
void setup() {
attachInterrupt(0, AlarmPressed, RISING);
// Opne serial port
Serial.begin(9600);
while (!Serial) {
;
}
while ( status != WL_CONNECTED) {
Serial.print(" SSID: ");
Serial.println(ssid);
status = WiFi.begin(ssid, pass);
delay(1000); //
printWifiStatus();
Serial.println("Connecting to server");
}
}
void loop() {
if (client.available()) {
char c = client.read();
Serial.print(c);
client.stop();
}
if (!client.connected() && lastConnected) {
Serial.println("Disconnecting.");
Serial.println();
client.stop();
}
if(!client.connected() && (millis() - lastConnectionTime > postingInterval)) {
SendData();
}
lastConnected = client.connected();
} // Slutten paa loop
void AlarmPressed() {
btnpressed = true;
}
void SendData() {
// if there's a successful connection:
if (client.connect(server, port)) {
Serial.println("Connecting...");
// Send data til server:
if (btnpressed == false){
client.write("0");
Serial.print("No Alarm");
Serial.println();
btnpressed = false;
}
else {
client.write("1");
Serial.print("Alarm !");
Serial.println();
}
// note the time that the connection was made:
lastConnectionTime = millis();
}
else {
// if you couldn't make a connection:
Serial.println("Connection failed");
Serial.println("Disconnecting.");
Serial.println();
client.stop();
}
}
void printWifiStatus() {
Serial.print(" SSID: ");
Serial.println(WiFi.SSID());
// print your WiFi shield's IP address:
Serial.print("IP Address: ");
Serial.println(ip);
// print the received signal strength:
long rssi = WiFi.RSSI();
Serial.print("Signalstyrke til forbindelsen (RSSI):");
Serial.print(rssi);
Serial.println(" dBm");
}

Ethernet conflict with IRremote library

I have an arduino uno board with Ethernet shield. I use it to controlling lights with my relay. This is my code
#include <SPI.h>
#include <Ethernet.h>
#include <Time.h>
#include <Wire.h>
#include <DS1307RTC.h> // a basic DS1307 library that returns time as a time_t
// Enter a MAC address and IP address for your controller below.
byte mac[] = {0x90, 0xA2, 0xDA, 0x0D, 0x48, 0xD3 };
int lamp[] = {4, 7, 8, 9}; //pin buat relay
int lampAutoOnH[4];
int lampAutoOnM[4];
int lampAutoOffH[4];
int lampAutoOffM[4];
int j;
boolean lampAuto[4];
// The IP address will be dependent on your local network:
// assign an IP address for the controller:
byte ip[] = {192,168,0,20};
byte gateway[] = {192,168,0,1};
byte subnet[] = {255, 255, 255, 0};
// Initialize the Ethernet server library with the port you want to use.
EthernetServer server(80);
String readString;
// Declare Pin 8 as an LED because thats what we will be connecting the LED to.You could use any other pin and would then have to change the pin number.
void setup()
{
for(int i=0; i<4; i++){
pinMode(lamp[i], OUTPUT);
digitalWrite(lamp[i], LOW);
lampAuto[i] = false;
}
//trial with led, plug in to D1
//enable serial data print
Serial.begin(9600);
//start Ethernet
Ethernet.begin(mac, ip, gateway, subnet);
//Ethernet.begin(mac); //for DHCP
server.begin();
Serial.print("Server is at ");
Serial.println(Ethernet.localIP());
setSyncProvider(RTC.get); // the function to get the time from the RTC
if(timeStatus()!= timeSet)
Serial.println("Unable to sync with the RTC");
else{
Serial.println("RTC has set the system time");
printTime();
}
}
void loop()
{
// listen for incoming clients
EthernetClient client = server.available();
if (client){
while (client.connected()){
if (client.available()){
char c = client.read();
//read char by char HTTP request
if (readString.length() < 100){
//store characters to string
readString += c;
//Serial.print(c);
}
//Serial.write(c);
if (c == '\n') {
Serial.println(readString); //print to serial monitor for debuging
// Needed to Display Site:
client.println("HTTP/1.1 200 OK"); //send new page
client.println("Content-Type: text/html");
client.println();
client.println("<HTML>");
client.println("<HEAD>");
// what is being Displayed :
client.println("<TITLE>Home Automation</TITLE>");
client.println("<center>");
client.println("</HEAD>");
client.println("<BODY>");
client.println("<H1>Home Automation</H1>");
client.println("<hr />");
client.println("<center>");
client.println("Turn On Light1 ");
client.println(" Turn Off Light1<br /><br />");
client.println("Turn On Light2 ");
client.println(" Turn Off Light2<br /><br />");
client.println("Turn On Light3 ");
client.println(" Turn Off Light3<br /><br />");
client.println("Turn On Light4 ");
client.println(" Turn Off Light4<br /><br />");
client.println("Rekam IR<br /><br />");
client.println("Jika ingin mencoba auto, ketikkan : <br/><br/><b>");
client.println("http://192.168.1.20/?lightauto[angka][HHOn][MMOn][HHOff][MMOff]");
client.println("<b/></BODY>");
client.println("</HTML>");
delay(1);
cekLink();
printTime();
//stopping client
client.stop();
//clearing string for next read
readString="";
}
}
}
}
cekAuto();
}
void cekLink(){
// Code which needs to be Implemented:
if(readString.indexOf("?lighton") >0)//checks for on
{
String i = readString.substring(13, 14);
j = i.toInt()-1;
Serial.print("Lamp number '");
Serial.print(j+1);
Serial.print("' is on\nreadString = " + readString);
Serial.print(readString);
digitalWrite(lamp[j], HIGH);
lampAuto[j] = false;
}
else if(readString.indexOf("?lightoff") >0)//checks for off
{
String i = readString.substring(14, 15);
j = i.toInt()-1;
Serial.print("Lamp number '");
Serial.print(j+1);
Serial.print("' is off\nreadString = " + readString);
digitalWrite(lamp[j], LOW);
lampAuto[j] = false;
}else if(readString.indexOf("?lightauto") >0)//checks for on
{
//GET /?lightauto119171918
//0123456789012345678
String ll = readString.substring(15, 16);
String hhOn = readString.substring(16, 18);
String mmOn = readString.substring(18, 20);
String hhOff = readString.substring(20, 22);
String mmOff = readString.substring(22, 24);
j = ll.toInt()-1;
lampAuto[j] = true;
lampAutoOnH[j] = hhOn.toInt();
lampAutoOnM[j] = mmOn.toInt();
lampAutoOffH[j] = hhOff.toInt();
lampAutoOffM[j] = mmOff.toInt();
Serial.print("Lamp number '");
Serial.print(j+1);
Serial.print("' is auto. \n");
Serial.println("On at " + hhOn + ":" + mmOn);
Serial.println("Off at " + hhOff + ":" + mmOff);
Serial.print("readString = " + readString);
if(hour()>=lampAutoOnH[j])
digitalWrite(lamp[j], HIGH);
else if(hour()<=lampAutoOffH[j]&&minute()<=lampAutoOffM[j])
digitalWrite(lamp[j], HIGH);
else
digitalWrite(lamp[j], LOW);
}else if(readString.indexOf("?rekamIR") >0){
Serial.println("Rekam IR");
}
}
void printTime() {
Serial.print(hour());
printDigits(minute());
printDigits(second());
Serial.print(" ");
Serial.print(day());
Serial.print(" ");
Serial.print(month());
Serial.print(" ");
Serial.print(year());
Serial.println();
}
void printDigits(int digits){
//konversi waktu normal
Serial.print(":");
if(digits < 10)
Serial.print('0');
Serial.print(digits);
}
void cekAuto(){
for(int i=0; i<4; i++){
if(lampAuto[j]==true){
if(lampAutoOnH[i]==hour()&&lampAutoOnM[i]==minute())
digitalWrite(lamp[j], HIGH);
else if(lampAutoOffH[i]==hour()&&lampAutoOffM[i]==minute())
digitalWrite(lamp[j], LOW);
}
}
}
But when i add IRremote library to receive IR frequency,
#include <IRremote.h>
it doesn't work anymore. Can anyone help?

Send Mirf values with ethercard

I have project where I'm getting data over nRF24L01 and using Mirf to that. Now I'm working for Hub which need to send data to my webservice. For ethernet my choice was ENC28j60 with ethercard library.
Question : How I can wait data from Mirf and just send data forward with Ethercard browseUrl? I can send data without Mirf but there's some loop which I'm not understand.
My code :
#include <SPI.h>
#include <Mirf.h>
#include <nRF24L01.h>
#include <MirfHardwareSpiDriver.h>
#include <EtherCard.h>
// Set network settings
static byte mymac[] = { 0x74, 0x69, 0x69, 0x2D, 0x30, 0x31 };
byte Ethernet::buffer[700];
static uint32_t timer;
// My webservice
const char website[] PROGMEM = "my.webservice.com";
// Mirf variables
int tmpVal1;
// Local components
const int Yellow = 6;
const int Blue = 5;
void setup() {
Serial.begin(57600);
// Setup leds
pinMode(Yellow, OUTPUT);
digitalWrite(Yellow, LOW);
pinMode(Blue, OUTPUT);
digitalWrite(Blue, LOW);
setupMirf();
setupEthernet();
}
void loop() {
// Waiting to get date from Mirf
while (!Mirf.dataReady()) {
//ether.packetLoop(ether.packetReceive());
}
Mirf.getData((byte *)&tmpVal1);
Serial.print(tmpVal1);
Serial.println(F(" C"));
// Receive responses
ether.packetLoop(ether.packetReceive());
if (millis() > timer) {
timer = millis() + 5000;
//Serial.println();
Serial.println("Sending data to webservice : ");
ether.browseUrl(PSTR("/sendingdata.asmx/sendingdata?"), "Device=100&DeviceValue=80", website, my_callback);
}
//ShowLedNotification();
}
// called when the client request is complete
static void my_callback (byte status, word off, word len) {
Serial.println(">>>");
Ethernet::buffer[off+300] = 0;
Serial.print((const char*) Ethernet::buffer + off);
Serial.println("...");
digitalWrite(Blue,HIGH);
delay(200);
digitalWrite(Blue,LOW);
}
void ShowLedNotification() {
if (tmpVal1 > 0 ) {
digitalWrite(Yellow, HIGH);
delay(1000);
digitalWrite(Yellow, LOW);
}
else
{
digitalWrite(Blue, HIGH);
delay(1000);
digitalWrite(Blue, LOW);
}
}
long readVcc() {
long result;
// Read 1.1V reference against AVcc
ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
delay(2); // Wait for Vref to settle
ADCSRA |= _BV(ADSC); // Convert
while (bit_is_set(ADCSRA,ADSC));
result = ADCL;
result |= ADCH<<8;
result = 1126400L / result; // Back-calculate AVcc in mV
return result;
}
//Setting up network and getting DHCP IP
void setupEthernet() {
Serial.println(F("Setting up network and DHCP"));
Serial.print(F("MAC: "));
for (byte i = 0; i < 6; ++i) {
Serial.print(mymac[i], HEX);
if (i < 5)
Serial.print(':');
}
Serial.println();
if (ether.begin(sizeof Ethernet::buffer, mymac) == 0)
Serial.println(F("Failed to access Ethernet controller"));
Serial.println(F("Setting up DHCP"));
if (!ether.dhcpSetup())
Serial.println(F("DHCP failed"));
ether.printIp("My IP: ", ether.myip);
ether.printIp("Netmask: ", ether.netmask);
ether.printIp("GW IP: ", ether.gwip);
ether.printIp("DNS IP: ", ether.dnsip);
// Check network connection
if (!ether.dnsLookup(website))
Serial.println("DNS failed");
ether.printIp("SRV: ", ether.hisip);
}
void setupMirf() {
//Initialize nRF24
Serial.println(F("Initializing Mirf"));
Mirf.spi = &MirfHardwareSpi;
Mirf.init();
Mirf.setRADDR((byte *)"serv1");
Mirf.payload = sizeof(tmpVal1);
// we use channel 90 as it is outside of WLAN bands
// or channels used by wireless surveillance cameras
Mirf.channel = 90;
Mirf.config();
}
Did get that work. Now using if clause not while Mirf.dataReady()
void loop() {
if (Mirf.dataReady()) {
Mirf.getData((byte *)&tmpVal1);
Serial.print(tmpVal1);
Serial.println(F(" C"));
ShowLedNotification();
// Send data to webservice
if (millis() > timer) {
timer = millis() + 5000;
Serial.println("Sending data to webservice");
String myVarsStr = "Device=";
myVarsStr += myDeviceID;
myVarsStr += "&DeviceValue=";
myVarsStr += tmpVal1;
char myVarsCh[40];
myVarsStr.toCharArray(myVarsCh, 40);
ether.browseUrl(PSTR("/receivedata.asmx/ReceiveData?"), myVarsCh, website, my_callback);
}
}
else
{
word pos = ether.packetReceive();
word len = ether.packetLoop(pos);
delay(200);
}
}

Resources