예제 #1
0
void loop() {
  // if there's data available, read a packet
  int packetSize = Udp.parsePacket();
  char Size[4];
  if(packetSize)
  {
    if(packetSize == 4)
    {
      IPAddress remote = Udp.remoteIP();
    
      // read the packet into packetBufffer
      Udp.read(packetBuffer,UDP_TX_PACKET_MAX_SIZE);
      char Command[4];
      for(int nCom = 0; nCom < 4; nCom++)
        {
        Command[nCom] = packetBuffer[nCom];
        }
            
      if (Command[0] == 't')
      {
        digitalWrite(13, HIGH);
      }
      else if (Command[0] == 'r')
      {
        digitalWrite(12, HIGH);
      }
      else if (Command[0] == 'e')
      {
        digitalWrite(10, HIGH);
      }   
      else if (Command[0] == 'w')
      {
        analogWrite(11, 65);
      }      
      else
      {
        digitalWrite(13, LOW);
        digitalWrite(12, LOW);
        analogWrite(11, 0);
      }

      // send a reply, to the IP address and port that sent us the packet we received
      itoa(packetSize, Size, 10);
      Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
      Udp.write(ReplyBuffer);
      Udp.write(packetBuffer);
      Udp.write(Size);
      Udp.endPacket();
    delay(1000);
    }
    else
    {
      Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
      Udp.write("NOPE");
      Udp.endPacket();
    }
  }
}
예제 #2
0
void WakeOnLan::send(byte* mac, byte port, EthernetUDP udp) {

    byte preamble[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
	
    byte i;

    udp.beginPacket(_ip, port);
	
    udp.write(preamble, sizeof preamble);
    
    for (i = 0; i < 16; i++)
	
      udp.write(mac, sizeof mac);
      
    udp.endPacket();

#else // ARDUINO not defined or ARDUINO < 100

void WakeOnLan::send(byte* mac, byte port) {

	byte magic_packet[102] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
	
	for (byte i = 6; i < 102; i++)
	{
		magic_packet[i] = mac[i%6];		
	}
	
	Udp.sendPacket(magic_packet, 102, _ip, port);	

#endif // #if defined(ARDUINO) && ARDUINO >= 100

}
예제 #3
0
void sendNTPpacket(const byte *address)
/**
 * send an NTP request to the time server at the given address
 */
{
    // set all bytes in the buffer to 0
    memset(pb, 0, NTP_PACKET_SIZE);

    // Initialize values needed to form NTP request
    // (see URL above for details on the packets)
    pb[0] = 0b11100011;   // LI, Version, Mode
    pb[1] = 0;     // Stratum, or type of clock
    pb[2] = 6;     // Polling Interval
    pb[3] = 0xEC;  // Peer Clock Precision
    // 8 bytes of zero for Root Delay & Root Dispersion
    pb[12]  = 49;
    pb[13]  = 0x4E;
    pb[14]  = 49;
    pb[15]  = 52;

    // all NTP fields have been given values, now
    // you can send a packet requesting a timestamp:
    Udp.beginPacket(address, 123); //NTP requests are to port 123
    Udp.write(pb,NTP_PACKET_SIZE);
    Udp.endPacket();
}
예제 #4
0
void uartToUdp()
{
  bool sendIt = false;

  if (Serial.available() > 0)
  {
    uartBuffer[uartCounter] = Serial.read();
    if (uartBuffer[uartCounter] == HDLC_SS_BYTE)
    {
      if (hdlcStart)sendIt = true;
      else
      {
        hdlcStart = true;
        Timer1.start();
      }
    }
    else if (hdlcStart)
    {
      ++uartCounter;
    }
  }

  if (sendIt)
  {
    Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
    Udp.write(uartBuffer, uartCounter);
    Udp.endPacket();
    resetUartBuffer();
  }
}
예제 #5
0
roveEthernet_Error roveEthernet_SendUdpPacket(roveIP destIP, uint16_t destPort, const uint8_t* msg, size_t msgSize)
{
  udpReceiver.beginPacket(destIP, destPort);
  udpReceiver.write(msg, msgSize);
  udpReceiver.endPacket();
  return ROVE_ETHERNET_ERROR_SUCCESS;
}
예제 #6
0
// --------------------------------------------------- Ethernet Send Data -----------------------------------------------------------
void UDP_Send_Data()

{
	Udp.beginPacket(ip_rpi, rpi_port);
	Udp.write(nav.ch, sizeof(nav.data));
	Udp.write(cam.ch, sizeof(cam.pose));
	Udp.write(imu.ch, sizeof(imu.imu_data));
	Udp.endPacket();
}
예제 #7
0
파일: Udp.cpp 프로젝트: phord/master_clock
int sendUdp( char * data, int size )
{
  if ( ! active ) return 0 ;
  
  Udp.beginPacket(*timeServerAddress, serverPort);
  byte count = Udp.write((const unsigned char *)data,size);
  Udp.endPacket();
  return (int) count ;
}
예제 #8
0
void SNMPClass::writePacket(IPAddress address, uint16_t port, char *extra_data)
{
  Udp.beginPacket(address, port);
  Udp.write(_packet+_packetPos+1, _packetSize);
  
  if(extra_data != NULL){
    Udp.write((byte*)extra_data, _extra_data_size);
  }
  
  Udp.endPacket();
}
예제 #9
0
void SyslogClass::logger(uint8_t facility, uint8_t severity, const char tag[], const char message[]) {
        String Pri;

        Pri="<";
        Pri+=(8 * facility + severity);
        Pri+=">";
  
        char UDPBufferPri[Pri.length()+1];
        Pri.toCharArray(UDPBufferPri,Pri.length()+1);

        SyslogUdp.beginPacket(ip_syslogserver, SYSLOG_DEFAULT_PORT);

        SyslogUdp.write(UDPBufferPri);
        SyslogUdp.write(tag);
        SyslogUdp.write(" ");
        SyslogUdp.write(message);
        SyslogUdp.endPacket();
}
void Notification::sendUDPNotification(EthernetUDP &udpSocket, aJsonObject *pushurl_channel, char *payload1, extData payload2)
{
  Serial.print(F("Sending a UDP response: "));
  Serial.println(payload1);

  udpSocket.beginPacket(udpSocket.remoteIP(), udpSocket.remotePort());

  // The actual payload
  udpSocket.write(payload1);

  // Extra payload is generated by running a callback function
  if (payload2 != NULL)
  {
    (*payload2)(&udpSocket);
  }

  udpSocket.write("}"); // The end of the JSON data, i.e. '}'
  udpSocket.endPacket();
}
예제 #11
0
void sendNtpPacket(IPAddress& address)
{
	// set all bytes in the buffer to 0
	memset(packetBuffer, 0, NTP_PACKET_SIZE); 

	// Initialize values needed to form NTP request
	packetBuffer[0] = 0b11100011;   // LI, Version, Mode
	packetBuffer[1] = 0;     // Stratum, or type of clock
	packetBuffer[2] = 6;     // Polling Interval
	packetBuffer[3] = 0xEC;  // Peer Clock Precision

	// 8 bytes of zero for Root Delay & Root Dispersion
	packetBuffer[12]  = 49; 
	packetBuffer[13]  = 0x4E;
	packetBuffer[14]  = 49;
	packetBuffer[15]  = 52;

	// all NTP fields have been given values, now
	// you can send a packet requesting a timestamp:         
	Udp.beginPacket(address, 123); //NTP requests are to port 123
	Udp.write(packetBuffer,NTP_PACKET_SIZE);
	Udp.endPacket(); 
  
}
void commandInterfaceTick() {
  int packetSize = cmdsock.parsePacket();
  if(cmdsock.available()) {
    
    // read the packet into packetBufffer
    cmdsock.read(udpPacketBuffer, PACKET_SIZE);

    if(memcmp("INGV\0", udpPacketBuffer, 5) != 0) {
      return;
    }

    bool reboot = false;
    unsigned long unixTimeM = getUNIXTime();
    unsigned long uptime = getUNIXTime() - getBootTime();
    byte macaddress[6] = { 0 };
    getMACAddress(macaddress);
    uint32_t probeSpeed = getProbeSpeedStatistic();
    uint32_t freeramkb = freeMemory();
    float latency = 0;
    if(udpPacketBuffer[5] == PKTTYPE_GETINFO) {
      latency = tcpLatency();
    }

    float longitude = 0;
    float latitude = 0;

    switch(udpPacketBuffer[5]) {
      case PKTTYPE_DISCOVERY:
        // Reply to discovery
        udpPacketBuffer[5] = PKTTYPE_DISCOVERY_REPLY;

        memcpy(udpPacketBuffer + 6, macaddress, 6);
        
        memcpy(udpPacketBuffer + 12, getVersionAsString().c_str(), 4);
        memcpy(udpPacketBuffer + 16, "uno", 3);
        break;
      case PKYTYPE_PING:
        // Reply to ping
        udpPacketBuffer[5] = PKYTYPE_PONG;
        break;
      case PKTTYPE_SENDGPS:
        // Get coords
        udpPacketBuffer[5] = PKTTYPE_OK;

        memcpy(&latitude, udpPacketBuffer + 12, 4);
        memcpy(&longitude, udpPacketBuffer + 16, 4);
        reverse4bytes((byte*)&latitude);
        reverse4bytes((byte*)&longitude);
        
        break;
      case PKTTYPE_REBOOT:
        // Reboot
        // Reply with OK
        udpPacketBuffer[5] = PKTTYPE_OK;
        reboot = true;
        break;
      case PKTTYPE_GETINFO:
        udpPacketBuffer[5] = PKTTYPE_GETINFO_REPLY;

        memcpy(udpPacketBuffer + 6, macaddress, 6);
        memcpy(udpPacketBuffer + 28, &uptime, 4);
        memcpy(udpPacketBuffer + 32, &unixTimeM, 4);
        memcpy(udpPacketBuffer + 36, VERSION, 4);
        memcpy(udpPacketBuffer + 40, &freeramkb, 4);
        memcpy(udpPacketBuffer + 44, &latency, 4);
        memcpy(udpPacketBuffer + 53, "uno", 3);
        memcpy(udpPacketBuffer + 57, "MMA7361", 7);
        memcpy(udpPacketBuffer + 65, &probeSpeed, 4);

        break;
#ifdef RESET_ENABLED
      case PKTTYPE_RESET:
        initEEPROM();
        reboot = true;
        break;
#endif
      default:
        // Unknown packet or invalid command
        return;
    }

    if(longitude != 0 && latitude != 0) {
      setLongitude(longitude);
      setLatitude(latitude);
    }

    cmdsock.beginPacket(cmdsock.remoteIP(), cmdsock.remotePort());
    cmdsock.write(udpPacketBuffer, PACKET_SIZE);
    cmdsock.endPacket();
    cmdsock.flush();

    if(reboot) {
      soft_restart();
    }
  }
}
bool gatewayTransportSend(MyMessage &message)
{
	bool ret = true;
	char *_ethernetMsg = protocolFormat(message);

    setIndication(INDICATION_GW_TX);

	_w5100_spi_en(true);
	#if defined(MY_CONTROLLER_IP_ADDRESS)
		#if defined(MY_USE_UDP)
			_ethernetServer.beginPacket(_ethernetControllerIP, MY_PORT);
			_ethernetServer.write(_ethernetMsg, strlen(_ethernetMsg));
			// returns 1 if the packet was sent successfully
			ret = _ethernetServer.endPacket();
		#else
			EthernetClient client;
			#if defined(MY_CONTROLLER_URL_ADDRESS)
	                	if (client.connected() || client.connect(MY_CONTROLLER_URL_ADDRESS, MY_PORT)) {
	        	#else
	                	if (client.connected() || client.connect(_ethernetControllerIP, MY_PORT)) {
	        	#endif
	                	client.write(_ethernetMsg, strlen(_ethernetMsg));
	                }
	                else {
	                	// connecting to the server failed!
	                	ret = false;
	                }
		#endif
	#else
		// Send message to connected clients
		#if defined(MY_GATEWAY_ESP8266)
			for (uint8_t i = 0; i < ARRAY_SIZE(clients); i++)
			{
				if (clients[i] && clients[i].connected())
				{
					clients[i].write((uint8_t*)_ethernetMsg, strlen(_ethernetMsg));
				}
			}
		#else
			_ethernetServer.write(_ethernetMsg);
		#endif
	#endif
	_w5100_spi_en(false);
	return ret;

}


#if defined(MY_GATEWAY_ESP8266)
	bool _readFromClient(uint8_t i) {
		while (clients[i].connected() && clients[i].available()) {
			char inChar = clients[i].read();
			if (inputString[i].idx < MY_GATEWAY_MAX_RECEIVE_LENGTH - 1) {
				// if newline then command is complete
				if (inChar == '\n' || inChar == '\r') {
					// Add string terminator and prepare for the next message
					inputString[i].string[inputString[i].idx] = 0;
					debug(PSTR("Client %d: %s\n"), i, inputString[i].string);
					inputString[i].idx = 0;
					if (protocolParse(_ethernetMsg, inputString[i].string)) {
						return true;
					}

				} else {
					// add it to the inputString:
					inputString[i].string[inputString[i].idx++] = inChar;
				}
			} else {
				// Incoming message too long. Throw away
				debug(PSTR("Client %d: Message too long\n"), i);
				inputString[i].idx = 0;
				// Finished with this client's message. Next loop() we'll see if there's more to read.
				break;
			}
		}
		return false;
	}
#else
	bool _readFromClient() {
		while (client.connected() && client.available()) {
			char inChar = client.read();
			if (inputString.idx < MY_GATEWAY_MAX_RECEIVE_LENGTH - 1) {
				// if newline then command is complete
				if (inChar == '\n' || inChar == '\r') {
					// Add string terminator and prepare for the next message
					inputString.string[inputString.idx] = 0;
					debug(PSTR("Eth: %s\n"), inputString.string);
					inputString.idx = 0;
					if (protocolParse(_ethernetMsg, inputString.string)) {
						return true;
					}

				} else {
					// add it to the inputString:
					inputString.string[inputString.idx++] = inChar;
				}
			} else {
				// Incoming message too long. Throw away
				debug(PSTR("Eth: Message too long\n"));
				inputString.idx = 0;
				// Finished with this client's message. Next loop() we'll see if there's more to read.
				break;
			}
		}
		return false;
	}
#endif


bool gatewayTransportAvailable()
{
	_w5100_spi_en(true);
	#if !defined(MY_IP_ADDRESS) && defined(MY_GATEWAY_W5100)
		// renew IP address using DHCP
		gatewayTransportRenewIP();
	#endif

	#ifdef MY_USE_UDP

		int packet_size = _ethernetServer.parsePacket();

		if (packet_size) {
			//debug(PSTR("UDP packet available. Size:%d\n"), packet_size);
            setIndication(INDICATION_GW_RX);
			#if defined(MY_GATEWAY_ESP8266)
				_ethernetServer.read(inputString[0].string, MY_GATEWAY_MAX_RECEIVE_LENGTH);
				inputString[0].string[packet_size] = 0;
				debug(PSTR("UDP packet received: %s\n"), inputString[0].string);
				return protocolParse(_ethernetMsg, inputString[0].string);
			#else
				_ethernetServer.read(inputString.string, MY_GATEWAY_MAX_RECEIVE_LENGTH);
				inputString.string[packet_size] = 0;
				debug(PSTR("UDP packet received: %s\n"), inputString.string);
				_w5100_spi_en(false);
				return protocolParse(_ethernetMsg, inputString.string);
			#endif
		}
	#else
		#if defined(MY_GATEWAY_ESP8266)
			// ESP8266: Go over list of clients and stop any that are no longer connected.
			// If the server has a new client connection it will be assigned to a free slot.
			bool allSlotsOccupied = true;
			for (uint8_t i = 0; i < ARRAY_SIZE(clients); i++) {
				if (!clients[i].connected()) {
					if (clientsConnected[i]) {
						debug(PSTR("Client %d disconnected\n"), i);
						clients[i].stop();
					}
					//check if there are any new clients
					if (_ethernetServer.hasClient()) {
						clients[i] = _ethernetServer.available();
						inputString[i].idx = 0;
						debug(PSTR("Client %d connected\n"), i);
						gatewayTransportSend(buildGw(_msg, I_GATEWAY_READY).set("Gateway startup complete."));
						if (presentation)
							presentation();
					}
				}
				bool connected = clients[i].connected();
				clientsConnected[i] = connected;
				allSlotsOccupied &= connected;
			}
			if (allSlotsOccupied && _ethernetServer.hasClient()) {
				//no free/disconnected spot so reject
				debug(PSTR("No free slot available\n"));
				EthernetClient c = _ethernetServer.available();
				c.stop();
			}
				// Loop over clients connect and read available data
			for (uint8_t i = 0; i < ARRAY_SIZE(clients); i++) {
				if (_readFromClient(i)) {
                    setIndication(INDICATION_GW_RX);
					_w5100_spi_en(false);
					return true;
				}
			}
		#else
			// W5100/ENC module does not have hasClient-method. We can only serve one client at the time.
			EthernetClient newclient = _ethernetServer.available();
			// if a new client connects make sure to dispose any previous existing sockets
			if (newclient) {
				if (client != newclient) {
					client.stop();
					client = newclient;
					debug(PSTR("Eth: connect\n"));
					_w5100_spi_en(false);
					gatewayTransportSend(buildGw(_msg, I_GATEWAY_READY).set("Gateway startup complete."));
					_w5100_spi_en(true);
					if (presentation)
						presentation();
				}
			}
			if (client) {
				if (!client.connected()) {
					debug(PSTR("Eth: disconnect\n"));
					client.stop();
				} else {
					if (_readFromClient()) {
                        setIndication(INDICATION_GW_RX);
						_w5100_spi_en(false);
						return true;
					}
				}
			}
		#endif
	#endif
	_w5100_spi_en(false);
	return false;
}
예제 #14
0
파일: Agentuino.cpp 프로젝트: 1sw/Agentuino
SNMP_API_STAT_CODES AgentuinoClass::responsePdu(SNMP_PDU *pdu)
{
	int32_u u;
	byte i;
	//
	// Length of entire SNMP packet
	_packetPos = 0;  // 23
	_packetSize = 25 + sizeof(pdu->requestId) + sizeof(pdu->error) + sizeof(pdu->errorIndex) + pdu->OID.size + pdu->VALUE.size;
	//
	memset(_packet, 0, SNMP_MAX_PACKET_LEN);
	//
	if ( _dstType == SNMP_PDU_SET ) {
		_packetSize += _setSize;
	} else {
		_packetSize += _getSize;
	}
	//
	_packet[_packetPos++] = (byte)SNMP_SYNTAX_SEQUENCE;	// type
	_packet[_packetPos++] = (byte)_packetSize - 2;		// length
	//
	// SNMP version
	_packet[_packetPos++] = (byte)SNMP_SYNTAX_INT;	// type
	_packet[_packetPos++] = 0x01;			// length
	_packet[_packetPos++] = 0x00;			// value
	//
	// SNMP community string
	_packet[_packetPos++] = (byte)SNMP_SYNTAX_OCTETS;	// type
	if ( _dstType == SNMP_PDU_SET ) {
		_packet[_packetPos++] = (byte)_setSize;	// length
		for ( i = 0; i < _setSize; i++ ) {
			_packet[_packetPos++] = (byte)_setCommName[i];
		}
	} else {
		_packet[_packetPos++] = (byte)_getSize;	// length
		for ( i = 0; i < _getSize; i++ ) {
			_packet[_packetPos++] = (byte)_getCommName[i];
		}
	}
	//
	// SNMP PDU
	_packet[_packetPos++] = (byte)pdu->type;
	_packet[_packetPos++] = (byte)( sizeof(pdu->requestId) + sizeof((int32_t)pdu->error) + sizeof(pdu->errorIndex) + pdu->OID.size + pdu->VALUE.size + 14 );
	//
	// Request ID (size always 4 e.g. 4-byte int)
	_packet[_packetPos++] = (byte)SNMP_SYNTAX_INT;	// type
	_packet[_packetPos++] = (byte)sizeof(pdu->requestId);
	u.int32 = pdu->requestId;
	_packet[_packetPos++] = u.data[3];
	_packet[_packetPos++] = u.data[2];
	_packet[_packetPos++] = u.data[1];
	_packet[_packetPos++] = u.data[0];
	//
	// Error (size always 4 e.g. 4-byte int)
	_packet[_packetPos++] = (byte)SNMP_SYNTAX_INT;	// type
	_packet[_packetPos++] = (byte)sizeof((int32_t)pdu->error);
	u.int32 = pdu->error;
	_packet[_packetPos++] = u.data[3];
	_packet[_packetPos++] = u.data[2];
	_packet[_packetPos++] = u.data[1];
	_packet[_packetPos++] = u.data[0];
	//
	// Error Index (size always 4 e.g. 4-byte int)
	_packet[_packetPos++] = (byte)SNMP_SYNTAX_INT;	// type
	_packet[_packetPos++] = (byte)sizeof(pdu->errorIndex);
	u.int32 = pdu->errorIndex;
	_packet[_packetPos++] = u.data[3];
	_packet[_packetPos++] = u.data[2];
	_packet[_packetPos++] = u.data[1];
	_packet[_packetPos++] = u.data[0];
	//
	// Varbind List
	_packet[_packetPos++] = (byte)SNMP_SYNTAX_SEQUENCE;	// type
	_packet[_packetPos++] = (byte)( pdu->OID.size + pdu->VALUE.size + 6 ); //4
	//
	// Varbind
	_packet[_packetPos++] = (byte)SNMP_SYNTAX_SEQUENCE;	// type
	_packet[_packetPos++] = (byte)( pdu->OID.size + pdu->VALUE.size + 4 ); //2
	//
	// ObjectIdentifier
	_packet[_packetPos++] = (byte)SNMP_SYNTAX_OID;	// type
	_packet[_packetPos++] = (byte)(pdu->OID.size);
	for ( i = 0; i < pdu->OID.size; i++ ) {
		_packet[_packetPos++] = pdu->OID.data[i];
	}
	//
	// Value
	_packet[_packetPos++] = (byte)pdu->VALUE.syntax;	// type
	_packet[_packetPos++] = (byte)(pdu->VALUE.size);
	for ( i = 0; i < pdu->VALUE.size; i++ ) {
		_packet[_packetPos++] = pdu->VALUE.data[i];
	}
	//
	Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
	Udp.write(_packet, _packetSize);
	Udp.endPacket();
//	Udp.write(_packet, _packetSize, _dstIp, _dstPort);
	//
	return SNMP_API_STAT_SUCCESS;
}
예제 #15
0
/**
 * Copies an external byte array into _packet and then sends it out.
 * 
 * Original Auther: Rex Park
 * Added: November 8, 2015 (Designed to be used with a system that resends informs that haven't been acknowledged)
 */
void SNMPClass::send_message(IPAddress address, uint16_t port, byte *packet, uint16_t packet_size){
  Udp.beginPacket(address, port);
  Udp.write(packet, packet_size);
  Udp.endPacket();
}
예제 #16
0
/**
 *
 * @info function for send SNMP TRAP
 * @param message
 * @param IP address recipient
 * @param boot time
 * @param enterprise OID
 * @param OID
 * @return void
 */
void AgentuinoClass::Trap(char Message[], byte RemIP[4], uint32_t Time, char enterprise_oid[], char oid_[]) {

    SNMP_OID oid;

    // trap = sequence, leng = pdu leng
    byte Type_and_leng[2] = {48, 0};

    // type = integer, leng = 1, value = 0 - snmp v1
    byte Version[3] = {2, 1, 0}; // Defined versión 1

    // type = octet string, leng = , value = comunity string
    byte Comunity_string[2 + strlen(_getCommName)];
    Comunity_string[0] = 4;
    Comunity_string[1] = strlen(_getCommName);

    for (uint8_t i = 2; i <= strlen(_getCommName) + 1; i++)
        Comunity_string[i] = (int) _getCommName[i - 2];

    // type = trap-pdu, 82, 0, leng = long as the other message
    byte PDU_type_and_leng[4] = {164, 130, 0, 53 + strlen(Message)};

    // type = identifier, leng = leng oid, value = oid
    size_t oid_size = 0;
    byte *enterprise_oid_dec = oid.fromString(enterprise_oid, oid_size);

    byte OID[2 + oid_size];
    OID[0] = 6;
    OID[1] = oid_size;

    for (int i = 2; i < oid_size + 2; i++)
        OID[i] = enterprise_oid_dec[i - 2];

    // type = IP, leng = 4, value - IP sender
    byte IP_definition[2] = {64, 4};

    // type = integer, leng = 1, value = 6 - trap type
    byte Type_Trap[3] = {2, 1, 6};

    // type = 1, leng = 1, value = 1 - specific trap number
    byte extra_OID[3] = {2, 1, 1};

    // type = time stick, leng = 4
    byte Type_time_stick[2] = {67, 4};

    // The next part is to change the locUpTime into bytes
    int i = 0, k = 1, temp;
    byte suma = 0;
    uint32_t quotient;
    quotient = Time;
    byte hexadecimalNumber[4] = {0, 0, 0, 0};
    while (quotient != 0) {
        temp = quotient % 16;
        if (k == 1) {
            suma = temp;
            k = 2;
        } else {
            suma = suma + temp * 16;
            hexadecimalNumber[3 - i] = suma;
            i = i + 1;
            k = 1;
        }
        quotient = quotient / 16;
    }

    if (k == 2) {
        hexadecimalNumber[3 - i] = suma;
    }

    // type = sequence, 130, 0, leng =  long as the other message
    byte Var_Bind[4] = {48, 130, 0, 20 + strlen(Message)}; // Here is defined the size

    // type = sequence, 130, 0, leng = long as the other message
    byte Var_Bind1[4] = {48, 130, 0, 16 + strlen(Message)}; // Here is defined the size

    // type = intetifier, leng = leng oid, value = oid
    oid_size = 0;
    byte *oid_dec = oid.fromString(oid_, oid_size);

    byte OID1[2 + oid_size];
    OID1[0] = 6;
    OID1[1] = oid_size;

    for (int i = 2; i < oid_size + 2; i++)
        OID1[i] = oid_dec[i - 2];

    // type = octetstring, leng = long as the other message, value = message
    byte Value1[2] = {4, strlen(Message)};

    Type_and_leng[1] = sizeof (Version) / sizeof (Version[0]) + sizeof (Comunity_string) / sizeof (Comunity_string[0])
            + sizeof (PDU_type_and_leng) / sizeof (PDU_type_and_leng[0]) + sizeof (OID) / sizeof (OID[0])
            + sizeof (IP_definition) / sizeof (IP_definition[0]) + sizeof (my_IP_address) / sizeof (my_IP_address[0])
            + sizeof (Type_Trap) / sizeof ( Type_Trap[0]) + sizeof (extra_OID) / sizeof ( extra_OID[0])
            + sizeof (Type_time_stick) / sizeof ( Type_time_stick[0]) + sizeof (hexadecimalNumber) / sizeof ( hexadecimalNumber[0])
            + sizeof (Var_Bind) / sizeof ( Var_Bind[0]) + sizeof (Var_Bind1) / sizeof ( Var_Bind1[0])
            + sizeof (OID1) / sizeof ( OID1[0]) + sizeof (Value1) / sizeof (Value1[0]) + strlen(Message);

    Var_Bind[3] = 6 + strlen(Message) + (sizeof (OID1) / sizeof ( OID1[0]));
    Var_Bind1[3] = 2 + strlen(Message) + (sizeof (OID1) / sizeof ( OID1[0]));

    PDU_type_and_leng[3] = sizeof (OID) / sizeof (OID[0])
            + sizeof (IP_definition) / sizeof (IP_definition[0]) + sizeof (my_IP_address) / sizeof (my_IP_address[0])
            + sizeof (Type_Trap) / sizeof ( Type_Trap[0]) + sizeof (extra_OID) / sizeof ( extra_OID[0])
            + sizeof (Type_time_stick) / sizeof ( Type_time_stick[0]) + sizeof (hexadecimalNumber) / sizeof ( hexadecimalNumber[0])
            + sizeof (Var_Bind) / sizeof ( Var_Bind[0]) + sizeof (Var_Bind1) / sizeof ( Var_Bind1[0])
            + sizeof (OID1) / sizeof ( OID1[0]) + sizeof (Value1) / sizeof (Value1[0]) + strlen(Message);

    Udp.beginPacket(RemIP, 162); // Here is defined the UDP port 162 to send the trap
    Udp.write(Type_and_leng, 2);
    Udp.write(Version, 3);
    Udp.write(Comunity_string, 2 + strlen(_getCommName));
    Udp.write(PDU_type_and_leng, 4);
    Udp.write(OID, sizeof (OID) / sizeof (OID[0]));
    Udp.write(IP_definition, 2);
    Udp.write(my_IP_address, 4);
    Udp.write(Type_Trap, 3);
    Udp.write(extra_OID, 3);
    Udp.write(Type_time_stick, 2);
    Udp.write(hexadecimalNumber, 4);
    Udp.write(Var_Bind, 4);
    Udp.write(Var_Bind1, 4);
    Udp.write(OID1, sizeof (OID1) / sizeof (OID1[0]));
    Udp.write(Value1, 2);
    Udp.write(Message, strlen(Message));
    Udp.endPacket();
}