Code Monkey home page Code Monkey logo

Comments (3)

Hawkfree avatar Hawkfree commented on May 20, 2024 1

I found the solution:
Convert data in loop{} not before sending packet.

global declaration:
char dataChar[51];

///////////////////////////////////////////////////////////////////////////////////////////////////////
void loop () { 
  ethPaket = ether.packetLoop(ether.packetReceive());
  if(ethPaket) prijemPaketu();
  wdt_reset();         
  if (millis() > timer + 5000) 
  {
    timer = millis();
    power=random(1, 5000);
    t=random(-50, 50);

    dataString = ArduinoID + "&t1=" + t + "&power=" + power + "\r\n";
    dataString.toCharArray(dataChar, 50); 
    
    odeslaniPaketu(dataChar);
  } 
}//end loop

//////////////////////////////////////////////////
void odeslaniPaketu(char dataChar[]){
  ether.browseUrl(PSTR("/shome/arduino/elektromer.php?"), dataChar, server, callback);
}

from minicore.

MCUdude avatar MCUdude commented on May 20, 2024

Can you isolate the problem please (smallest code possible while still being able to demonstrate the problem), and then upload the code so I'm able to test it myself?

from minicore.

Hawkfree avatar Hawkfree commented on May 20, 2024

Here's the code:

/* 
 *  Test program
 *  seding data to server 192,168,0,104
*/
#include <EtherCard.h>
#include <avr/wdt.h>
/********************************************************************/
#define DEBUG (true)

String ArduinoID= "ID=03";
static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x33,0x43 };
static byte myip[] = { 192,168,0,36 };
static byte gwip[] = { 192,168,0,1 };
static byte server[] = { 192,168,0,104 };

byte Ethernet::buffer[400]; // tcp ip send and receive buffer
int t,power;

unsigned long timer = millis(); 
uint16_t ethPaket;
String dataString;
const char pageOk[] PROGMEM ="HTTP/1.0 200 OK\r\n Content-Type: text/html\r\n\r\nOK";
/////////////////////////////////////////////////////////////////// called when the client request is complete
static void callback (byte status, word off, word len) {
  Ethernet::buffer[off+300] = 0;
  if DEBUG Serial.println((const char*) Ethernet::buffer + off);   
}
////////////////////////////////////////////////////////////////////////////////////////
void setup () {
  if DEBUG Serial.begin(115200);
  if DEBUG Serial.println(F("Start - DEBUG ON"));
  wdt_enable(WDTO_4S);
  init_ethernet();
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////
void loop () { 

  ethPaket = ether.packetLoop(ether.packetReceive());
  if(ethPaket) prijemPaketu();//dotaz na http
  wdt_reset();         
  if (millis() > timer + 5000) 
  {
    timer = millis();
    power=random(1, 5000);
    t=random(-50, 50);

    dataString = ArduinoID + "&t1=" + t + "&power=" + power + "\r\n";
    odeslaniPaketu(dataString);
  } 
}//end loop
/////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////
void odeslaniPaketu(String dataString){

  char dataChar[dataString.length()+1];
  dataString.toCharArray(dataChar, dataString.length()); 
  if DEBUG Serial.println(dataChar);    
  if DEBUG Serial.print(F("<<< REQ "));

  ether.browseUrl(PSTR("/shome/arduino/elektromer.php?"), dataChar, server, callback);
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////
void prijemPaketu(){
  if DEBUG Serial.println(F("<<<------------->>>"));      
  char* data = (char *) Ethernet::buffer + ethPaket;

  if DEBUG Serial.println(data);

  memcpy_P(ether.tcpOffset(), pageOk, sizeof pageOk);
  ether.httpServerReply(sizeof pageOk - 1);
}
////////////////////////////////////////////////////////////////////////////////////////////////
void init_ethernet(void){  
  if (ether.begin(sizeof Ethernet::buffer, mymac,10)== 0) 
    if DEBUG Serial.println(F("Failed Ethernet controller"));

  if (!ether.dhcpSetup()){
    ether.staticSetup(myip, gwip);
    if DEBUG Serial.println(F("No DHCP, Static IP!"));
  }
  
  ether.copyIp(ether.hisip, server);
      
  if DEBUG{ 
      ether.printIp("IP: ", ether.myip);
      ether.printIp("GW: ", ether.gwip);
      ether.printIp("DNS: ", ether.dnsip);
      ether.printIp("DHCP: ", ether.dhcpip); // output IP address of the DHCP server
      ether.printIp("SRV: ", ether.hisip);
  } 
}
////////////////////////////////////////////////////////////////////////////////////////////////

from minicore.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.